You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/05/31 13:56:03 UTC

svn commit: r543121 [6/6] - in /activemq/activemq-cpp/trunk/src/decaf: io/ lang/ lang/exceptions/ net/ util/ util/concurrent/ util/logging/

Added: activemq/activemq-cpp/trunk/src/decaf/util/logging/PropertiesChangeListener.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/util/logging/PropertiesChangeListener.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/util/logging/PropertiesChangeListener.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/util/logging/PropertiesChangeListener.h Thu May 31 04:55:59 2007
@@ -0,0 +1,48 @@
+/*
+ * 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_PROPERTIESCHANGELISTENER_H_
+#define _DECAF_UTIL_LOGGING_PROPERTIESCHANGELISTENER_H_
+
+namespace decaf{
+namespace util{
+namespace logging{
+
+   /**
+    * Defines the interface that classes can use to listen for change
+    * events on Properties.
+    */
+   class PropertiesChangeListener
+   {
+   public:
+
+      virtual ~PropertiesChangeListener() {}
+
+      /**
+       * Change Event, called when a property is changed
+       * @param name - Name of the Property
+       * @param oldValue - Old Value of the Property
+       * @param newValue - New Value of the Property
+       */
+      virtual void onPropertyChanged( const std::string& name,
+                                      const std::string& oldValue,
+                                      const std::string& newValue ) = 0;
+
+   };
+
+}}}
+
+#endif /*_DECAF_UTIL_LOGGING_PROPERTIESCHANGELISTENER_H_*/

Added: activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleFormatter.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleFormatter.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleFormatter.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleFormatter.h Thu May 31 04:55:59 2007
@@ -0,0 +1,76 @@
+/*
+ * 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_SIMPLEFORMATTER_H_
+#define _DECAF_UTIL_LOGGING_SIMPLEFORMATTER_H_
+
+#include <decaf/util/logging/formatter.h>
+
+namespace decaf{
+namespace util{
+namespace logging{
+
+    /**
+     * Print a brief summary of the LogRecord in a human readable format.
+     * The summary will typically be 1 or 2 lines.
+     */
+    class SimpleFormatter : public Formatter {
+    public:
+
+        SimpleFormatter() {}
+        virtual ~SimpleFormatter() {}
+
+        /**
+         * Format the given log record and return the formatted string.
+         * @param record The Log Record to Format
+         */
+        virtual std::string format( const LogRecord& record ) const {
+            return "";
+        }
+
+        /**
+         * Format the message string from a log record.
+         * @param record The Log Record to Format
+         */
+         virtual std::string formatMessage( const LogRecord& record ) const{
+            return record.getMessage();
+        }
+
+        /**
+         * Return the header string for a set of formatted records.  In the
+         * default implementation this method should return empty string
+         * @param handler the target handler, can be null
+         * @return empty string
+         */
+        virtual std::string getHead( const Handler* handler ) {
+            return "";
+        }
+
+        /**
+         * Return the tail string for a set of formatted records.  In the
+         * default implementation this method should return empty string
+         * @param handler the target handler, can be null
+         * @return empty string
+         */
+        virtual std::string getTail( const Handler* handler ) {
+            return "";
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_UTIL_LOGGING_SIMPLEFORMATTER_H_*/

Added: activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.cpp?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.cpp Thu May 31 04:55:59 2007
@@ -0,0 +1,80 @@
+/*
+ * 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 "SimpleLogger.h"
+
+#include <iostream>
+#include <decaf/util/logging/LogWriter.h>
+
+using namespace std;
+using namespace activemq;
+using namespace activemq::concurrent;
+using namespace decaf::util::logging;
+
+////////////////////////////////////////////////////////////////////////////////
+SimpleLogger::SimpleLogger( const std::string& name )
+{
+    this->name = name;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+SimpleLogger::~SimpleLogger()
+{}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::mark( const std::string& message ) {
+    LogWriter::getInstance().log( "", 0, "", message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::debug( const std::string& file,
+                          const int          line,
+                          const std::string& message ) {
+    LogWriter::getInstance().log( file, line, "DEBUG:", message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::info( const std::string& file,
+                         const int          line,
+                         const std::string& message ) {
+    LogWriter::getInstance().log( file, line, "INFO:", message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::warn( const std::string& file,
+                         const int          line,
+                         const std::string& message ) {
+    LogWriter::getInstance().log( file, line, "WARNING:", message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::error( const std::string& file,
+                          const int          line,
+                          const std::string& message ) {
+    LogWriter::getInstance().log( file, line, "ERROR:", message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::fatal( const std::string& file,
+                          const int          line,
+                          const std::string& message ) {
+    LogWriter::getInstance().log( file, line, "FATAL:", message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SimpleLogger::log(const std::string& message ) {
+    LogWriter::getInstance().log( message );
+}

Added: activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/util/logging/SimpleLogger.h Thu May 31 04:55:59 2007
@@ -0,0 +1,94 @@
+/*
+ * 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_SIMPLELOGGER_H_
+#define _DECAF_UTIL_LOGGING_SIMPLELOGGER_H_
+
+#include <string>
+
+namespace decaf{
+namespace util{
+namespace logging{
+
+   class SimpleLogger
+   {
+   public:
+
+      /**
+       * Constructor
+       */
+      SimpleLogger( const std::string& name );
+
+      /**
+       * Destructor
+       */
+      virtual ~SimpleLogger();
+
+      /**
+       * Log a Mark Block Level Log
+       */
+      virtual void mark(const std::string& message);
+
+      /**
+       * Log a Debug Level Log
+       */
+      virtual void debug(const std::string& file,
+                         const int          line,
+                         const std::string& message);
+
+      /**
+       * Log a Informational Level Log
+       */
+      virtual void info(const std::string& file,
+                        const int          line,
+                        const std::string& message);
+
+      /**
+       * Log a Warning Level Log
+       */
+      virtual void warn(const std::string& file,
+                        const int          line,
+                        const std::string& message);
+
+      /**
+       * Log a Error Level Log
+       */
+      virtual void error(const std::string& file,
+                         const int          line,
+                         const std::string& message);
+
+      /**
+       * Log a Fatal Level Log
+       */
+      virtual void fatal(const std::string& file,
+                         const int          line,
+                         const std::string& message);
+
+      /**
+       * No-frills log.
+       */
+      virtual void log(const std::string& message);
+
+   private:
+
+      // Name of this Logger
+      std::string name;
+
+   };
+
+}}}
+
+#endif /*_DECAF_UTIL_LOGGING_SIMPLELOGGER_H_*/

Added: activemq/activemq-cpp/trunk/src/decaf/util/logging/StreamHandler.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/util/logging/StreamHandler.h?view=auto&rev=543121
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/util/logging/StreamHandler.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/util/logging/StreamHandler.h Thu May 31 04:55:59 2007
@@ -0,0 +1,217 @@
+/*
+ * 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_STREAMHANDLER_H_
+#define _DECAF_UTIL_LOGGING_STREAMHANDLER_H_
+
+#include <decaf/util/logging/LoggerCommon.h>
+#include <decaf/util/logging/Handler.h>
+#include <decaf/util/logging/Formatter.h>
+#include <decaf/util/logging/Filter.h>
+#include <activemq/io/OutputStream.h>
+#include <activemq/exceptions/NullPointerException.h>
+#include <activemq/exceptions/InvalidStateException.h>
+#include <activemq/concurrent/Concurrent.h>
+
+namespace decaf{
+namespace util{
+namespace logging{
+
+    class StreamHandler : public Handler {
+    private:
+
+        // OutputStream to write to
+        io::OutputStream* stream;
+
+        // Formats this Handlers output
+        Formatter* formatter;
+
+        // Filter object for Log Filtering
+        Filter* filter;
+
+    public:
+
+        /**
+         * Create a StreamHandler, with no current output stream.
+         */
+        StreamHandler() {
+            this->stream = NULL;
+            this->formatter = NULL;
+            this->filter = NULL;
+
+            this->level = Level::FATAL;  // We take everything by default
+        }
+
+        /**
+         * Create a StreamHandler, with no current output stream.
+         */
+        StreamHandler( io::OutputStream* stream, Formatter* formatter )
+        {
+            this->stream = stream;
+            this->formatter = formatter;
+            this->filter = NULL;
+
+           this->level = Level::Fatal;  // We take everything by default
+        }
+
+        /**
+         * Destructor
+         */
+        virtual ~StreamHandler() {
+            try {
+                this->close();
+            }
+            AMQ_CATCH_NOTHROW( lang::Exception)
+            AMQ_CATCALL_NOTHROW()
+        }
+
+        /**
+         * Close the current output stream.
+         * <p>
+         * The close method will perform a flush and then close the Handler.
+         * After close has been called this Handler  should no longer be used.
+         * Method calls may either be silently ignored or may throw runtime
+         * exceptions.
+         * @throw CMSException
+         */
+        virtual void close() throw ( cms::CMSException ) {
+            if( stream ) {
+                stream.flush();
+                stream.close();
+            }
+        }
+
+        /**
+         * Flush the Handler's output, clears any buffers.
+         */
+        virtual void flush() {
+            if(stream) {
+                stream->flush();
+            }
+        }
+
+        /**
+         * Publish the Log Record to this Handler
+         * @param The Log Record to Publish
+         */
+        virtual void publish( const LogRecord& record ) {
+
+            try {
+
+                if( !stream ) {
+                    throw lang::exceptions::NullPointerException(
+                        __FILE__, __LINE__,
+                        "StreamHandler::publish - Stream not set.");
+                }
+
+                // Check if we should log this record
+                if(isLoggable( record) ) {
+
+                    std::string log = formatter->format(record);
+
+                    synchronized(stream) {
+                        // Write the data to the stream
+                        stream->write(log.c_str(), log.length());
+                    }
+                }
+            }
+            AMQ_CATCH_RETHROW( lang::Exception )
+            AMQ_CATCHALL_THROW( lang::Exception )
+        }
+
+        /**
+         * Check if this Handler would actually log a given LogRecord.
+         * <p>
+         * @param <code>LogRecord</code> to check
+         */
+        virtual void isLoggable( const LogRecord& record ) {
+
+            if( filter ) {
+                // Allow for some filtering to occurr
+                return filter->isLoggable( record );
+            }
+
+            // By default we want everything that is greater than or
+            // equal to the set level of this Handler.
+            return record.level >= level;
+        }
+
+        /**
+         * Sets the Filter that this Handler uses to filter Log Records
+         * @param <code>Filter</code> derived instance
+         */
+        virtual void setFilter( const Filter* filter ){
+            this->filter = filter;
+        }
+
+        /**
+         * Gets the Filter that this Handler uses to filter Log Records
+         * @param <code>Filter</code> derived instance
+         */
+        virtual const Filter* getFilter(){
+            return filter;
+        }
+
+        /**
+         * Set the log level specifying which message levels will be logged
+         * by this Handler.
+         * <p>
+         * The intention is to allow developers to turn on voluminous logging,
+         * but to limit the messages that are sent to certain Handlers.
+         * @param Level enumeration value
+         */
+        virtual void setLevel( Level level ){
+            this->level = level;
+        }
+
+        /**
+         * Get the log level specifying which message levels will be logged
+         * by this Handler.
+         * @param Level enumeration value
+         */
+        virtual Level getLevel(){
+            return level;
+        }
+
+        /**
+         * Sets the <code>Formatter</code> used by this Handler
+         * @param <code>Filter</code> derived instance
+         */
+        virtual void setFormatter( const Formatter* formatter ){
+            this->formatter = formatter;
+        }
+
+        /**
+         * Gets the <code>Formatter</code> used by this Handler
+         * @param <code>Filter</code> derived instance
+         */
+        virtual const Formatter* getFormatter(){
+            return formatter;
+        }
+
+        /**
+         * Gets the output Stream that this Handler is using
+         * @return OuputStream pointer
+         */
+        virtual io::OutputStream* getOutputStream() const(
+            return stream;
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_UTIL_LOGGING_STREAMHANDLER_H_*/