Author: tabish
Date: Wed Feb 10 00:25:16 2010
New Revision: 908291
URL: http://svn.apache.org/viewvc?rev=908291&view=rev
Log:
Some more work on the Logger Package.
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.cpp
(with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.h
(with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/SimpleFormatter.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=908291&r1=908290&r2=908291&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Wed Feb 10
00:25:16 2010
@@ -570,7 +570,8 @@
decaf/util/logging/LoggerHierarchy.cpp \
decaf/util/logging/SimpleFormatter.cpp \
decaf/util/logging/SimpleLogger.cpp \
- decaf/util/logging/StreamHandler.cpp
+ decaf/util/logging/StreamHandler.cpp \
+ decaf/util/logging/XMLFormatter.cpp
h_sources = \
@@ -1302,7 +1303,8 @@
decaf/util/logging/PropertiesChangeListener.h \
decaf/util/logging/SimpleFormatter.h \
decaf/util/logging/SimpleLogger.h \
- decaf/util/logging/StreamHandler.h
+ decaf/util/logging/StreamHandler.h \
+ decaf/util/logging/XMLFormatter.h
##
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/SimpleFormatter.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/SimpleFormatter.cpp?rev=908291&r1=908290&r2=908291&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/SimpleFormatter.cpp
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/SimpleFormatter.cpp
Wed Feb 10 00:25:16 2010
@@ -19,6 +19,11 @@
#include <decaf/util/logging/Level.h>
+#include <decaf/util/Date.h>
+
+#include <sstream>
+
+using namespace std;
using namespace decaf;
using namespace decaf::lang;
using namespace decaf::util;
@@ -34,5 +39,46 @@
////////////////////////////////////////////////////////////////////////////////
std::string SimpleFormatter::format( const LogRecord& record DECAF_UNUSED )
const {
- return "";
+
+ ostringstream stream;
+
+ stream << Date( record.getTimestamp() ).toString();
+ stream << " ";
+ stream << record.getSourceFile();
+ stream << ":";
+ stream << record.getSourceLine();
+ stream << std::endl;
+
+ stream << record.getLevel().getName();
+ stream << ": ";
+ stream << this->formatMessage( record );
+ stream << std::endl;
+
+ if( record.getThrown() != NULL ) {
+ stream << "Throwable occurred: ";
+ stream << std::endl;
+
+ // TODO write Stack Trace.
+ }
+// if (null != r.getThrown()) {
+// sb.append("Throwable occurred: "); //$NON-NLS-1$
+// Throwable t = r.getThrown();
+// PrintWriter pw = null;
+// try {
+// StringWriter sw = new StringWriter();
+// pw = new PrintWriter(sw);
+// t.printStackTrace(pw);
+// sb.append(sw.toString());
+// } finally {
+// if (pw != null) {
+// try {
+// pw.close();
+// } catch (Exception e) {
+// // ignore
+// }
+// }
+// }
+// }
+
+ return stream.str();
}
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.cpp?rev=908291&view=auto
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.cpp
(added)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.cpp
Wed Feb 10 00:25:16 2010
@@ -0,0 +1,132 @@
+/*
+ * 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 <decaf/lang/Throwable.h>
+#include <decaf/util/Date.h>
+
+#include <sstream>
+
+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>" << message << "</message>" << std::endl;
+ } else {
+ out << " <message/>" << std::endl;
+ }
+ }
+
+ void formatThrowable( const LogRecord& record, ostringstream& out ) {
+
+ Throwable* thrown = record.getThrown();
+ if( thrown != NULL ) {
+ out << " <exception>" << std::endl
+ << " <message>" << thrown->getMessage() << "</message>"
<< 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 << " <file>" << trace->first << "</file>" <<
std::endl;
+ out << " <line>" << trace->second << "</line>" <<
std::endl;
+ }
+
+ out << " <exception>" << std::endl;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+XMLFormatter::XMLFormatter() : Formatter() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+XMLFormatter::~XMLFormatter() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string XMLFormatter::format( const LogRecord& record ) const {
+
+ ostringstream out;
+
+ out << "<record>" << std::endl;
+ out << " <date>" << Date( record.getTimestamp() ).toString() <<
"</date>" << std::endl;
+
+ // TODO - Log Mills
+ // TODO - Log Sequence Number
+ //
sb.append(indent).append(("<sequence>")).append(r.getSequenceNumber())
+ // .append(("</sequence>")).append(lineSeperator);
+
+ if( "" != record.getLoggerName() ) {
+ out << " <logger>" << record.getLoggerName() << "</logger>" <<
std::endl;
+ }
+
+ out << " <level>" << record.getLevel().getName() << "</level>" <<
std::endl;
+
+ if( "" != record.getSourceFile() ) {
+ out << " <file>" << record.getSourceFile() << "</file>" << std::endl;
+ out << " <line>" << record.getSourceLine() << "</line>" << std::endl;
+ }
+
+ if( "" != record.getSourceFunction() ) {
+ out << " <method>" << record.getSourceFunction() << "</method>" <<
std::endl;
+ }
+
+ // TODO -Store Thread ID and log it.
+ //
sb.append(indent).append(("<thread>")).append(r.getThreadID()).append(
+ // ("</thread>")).append(lineSeperator);
+
+ formatMessages( record, out );
+ formatThrowable( record, out );
+
+ out << "</record>" << std::endl;
+
+ return out.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string XMLFormatter::getHead( const Handler* handler DECAF_UNUSED ) {
+
+ ostringstream out;
+
+ out << "<?xml version=\"1.0\" encoding=UTF-8\""
+ << "\" standalone=\"no\"?>"
+ << std::endl;
+
+ out << "<!DOCTYPE log SYSTEM \"logger.dtd\">" << std::endl;
+ out << "<log>";
+
+ return out.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string XMLFormatter::getTail( const Handler* handler DECAF_UNUSED ) {
+ return "</log>";
+}
Propchange:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.h?rev=908291&view=auto
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.h
(added)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.h
Wed Feb 10 00:25:16 2010
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_UTIL_LOGGING_XMLFORMATTER_H_
+#define _DECAF_UTIL_LOGGING_XMLFORMATTER_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/util/logging/Formatter.h>
+#include <decaf/util/logging/LogRecord.h>
+
+namespace decaf {
+namespace util {
+namespace logging {
+
+ /**
+ * Format a LogRecord into a standard XML format.
+ *
+ * TODO - Currently only outputs UTF-8
+ * The XMLFormatter can be used with arbitrary character encodings, but it
is
+ * recommended that it normally be used with UTF-8. The character encoding
can
+ * be set on the output Handler.
+ *
+ * @since 1.0
+ */
+ class DECAF_API XMLFormatter : public Formatter {
+ public:
+
+ XMLFormatter();
+
+ virtual ~XMLFormatter();
+
+ /**
+ * Converts a {...@code LogRecord} into an XML string.
+ *
+ * @param record
+ * The log record to be formatted.
+ *
+ * @return the log record formatted as an XML string.
+ */
+ virtual std::string format( const LogRecord& record ) const;
+
+ /**
+ * Returns the header string for a set of log records formatted as XML
+ * strings, using the output handler's encoding if it is defined,
otherwise
+ * using the default platform encoding.
+ *
+ * @param handler
+ * The output handler, may be {...@code null}.
+ *
+ * @return the header string for log records formatted as XML strings.
+ */
+ virtual std::string getHead( const Handler* handler );
+
+ /**
+ * Returns the tail string for a set of log records formatted as XML
+ * strings.
+ *
+ * @param handler
+ * The output handler, may be {...@code null}.
+ *
+ * @return the tail string for log records formatted as XML strings.
+ */
+ virtual std::string getTail( const Handler* handler );
+
+ };
+
+}}}
+
+#endif /* _DECAF_UTIL_LOGGING_XMLFORMATTER_H_ */
Propchange:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/logging/XMLFormatter.h
------------------------------------------------------------------------------
svn:eol-style = native