/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 "XMLFormatter.h" #include #include #include using namespace std; using namespace decaf; using namespace decaf::util; using namespace decaf::lang; using namespace decaf::util::logging; //////////////////////////////////////////////////////////////////////////////// namespace { void formatMessages( const LogRecord& record, ostringstream& out ) { std::string message = record.getMessage(); if( message != "" ) { out << " " << message << "" << std::endl; } else { out << " " << std::endl; } } void formatThrowable( const LogRecord& record, ostringstream& out ) { Throwable* thrown = record.getThrown(); if( thrown != NULL ) { out << " " << std::endl << " " << thrown->getMessage() << "" << std::endl; // format throwable's stack trace std::vector< std::pair< std::string, int> > stack = thrown->getStackTrace(); std::vector< std::pair< std::string, int> >::const_iterator trace = stack.begin(); for( ; trace != stack.end(); ++trace ) { out << " " << trace->first << "" << std::endl; out << " " << trace->second << "" << std::endl; } out << " " << std::endl; } } } //////////////////////////////////////////////////////////////////////////////// XMLFormatter::XMLFormatter() : Formatter() { } //////////////////////////////////////////////////////////////////////////////// XMLFormatter::~XMLFormatter() { } //////////////////////////////////////////////////////////////////////////////// std::string XMLFormatter::format( const LogRecord& record ) const { ostringstream out; out << "" << std::endl; out << " " << Date( record.getTimestamp() ).toString() << "" << std::endl; // TODO - Log Mills // TODO - Log Sequence Number // sb.append(indent).append(("")).append(r.getSequenceNumber()) // .append(("")).append(lineSeperator); if( "" != record.getLoggerName() ) { out << " " << record.getLoggerName() << "" << std::endl; } out << " " << record.getLevel().getName() << "" << std::endl; if( "" != record.getSourceFile() ) { out << " " << record.getSourceFile() << "" << std::endl; out << " " << record.getSourceLine() << "" << std::endl; } if( "" != record.getSourceFunction() ) { out << " " << record.getSourceFunction() << "" << std::endl; } // TODO -Store Thread ID and log it. // sb.append(indent).append(("")).append(r.getThreadID()).append( // ("")).append(lineSeperator); formatMessages( record, out ); formatThrowable( record, out ); out << "" << std::endl; return out.str(); } //////////////////////////////////////////////////////////////////////////////// std::string XMLFormatter::getHead( const Handler* handler DECAF_UNUSED ) { ostringstream out; out << "" << std::endl; out << "" << std::endl; out << ""; return out.str(); } //////////////////////////////////////////////////////////////////////////////// std::string XMLFormatter::getTail( const Handler* handler DECAF_UNUSED ) { return ""; }