/* * Copyright 2003,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include using namespace log4cxx; using namespace log4cxx::helpers; using namespace log4cxx::spi; IMPLEMENT_LOG4CXX_OBJECT(HTMLLayout) String HTMLLayout::TRACE_PREFIX =_T("
    "); String HTMLLayout::LOCATION_INFO_OPTION = _T("LocationInfo"); String HTMLLayout::TITLE_OPTION = _T("Title"); HTMLLayout::HTMLLayout() : locationInfo(false), title(_T("Log4cxx Log Messages")), dateFormat(TimeZone::getTimeZone(_T("GMT"))) { } void HTMLLayout::setOption(const String& option, const String& value) { if (StringHelper::equalsIgnoreCase(option, TITLE_OPTION)) { setTitle(value); } else if (StringHelper::equalsIgnoreCase(option, LOCATION_INFO_OPTION)) { setLocationInfo(OptionConverter::toBoolean(value, false)); } } void HTMLLayout::format(ostream& output, const spi::LoggingEventPtr& event) const { output << std::endl << _T("") << std::endl; output << _T(""); dateFormat.format(output, event->getTimeStamp()); output << _T("") << std::endl; output << _T("getThreadId() << _T(" thread\">"); output << event->getThreadId(); output << _T("") << std::endl; output << _T(""); if (event->getLevel()->equals(Level::DEBUG)) { output << _T(""); output << event->getLevel()->toString(); output << _T(""); } else if(event->getLevel()->isGreaterOrEqual(Level::WARN)) { output << _T(""); output << event->getLevel()->toString(); output << _T(""); } else { output << event->getLevel()->toString(); } output << _T("") << std::endl; output << _T("getLoggerName() << _T(" category\">"); Transform::appendEscapingTags(output, event->getLoggerName()); output << _T("") << std::endl; if(locationInfo) { USES_CONVERSION; output << _T(""); Transform::appendEscapingTags(output, A2T(event->getFile())); output.put(_T(':')); if (event->getLine() != 0) { output << event->getLine(); } output << _T("") << std::endl; } output << _T(""); Transform::appendEscapingTags(output, event->getRenderedMessage()); output << _T("") << std::endl; output << _T("") << std::endl; if (event->getNDC().length() != 0) { output << _T(""); output << _T("NDC: "); Transform::appendEscapingTags(output, event->getNDC()); output << _T("") << std::endl; } } void HTMLLayout::appendHeader(ostream& output) { output << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << title << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; output << _T("
") << std::endl; output << _T("Log session start time "); dateFormat.format(output, time(0)); output << _T("
") << std::endl; output << _T("
") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; output << _T("") << std::endl; if(locationInfo) { output << _T("") << std::endl; } output << _T("") << std::endl; output << _T("") << std::endl; } void HTMLLayout::appendFooter(ostream& output) { output << _T("
TimeThreadLevelCategoryFile:LineMessage
") << std::endl; output << _T("
") << std::endl; output << _T(""); }