BIND 10 trac2445, updated. 807cc540e16eedd53d714a4d9b61a2c24ae31c30 [2445] Some more cleanups

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Dec 10 10:52:59 UTC 2012


The branch, trac2445 has been updated
       via  807cc540e16eedd53d714a4d9b61a2c24ae31c30 (commit)
       via  2a69f5cd6a1badf9fb1538cd8f1ca56cef054ba7 (commit)
       via  7e30c020cd6c0babcf1d2c426ce72eb6a83a7fe4 (commit)
       via  17fb43189b8e6a8defa8f6e0a01b13d8ded65d16 (commit)
       via  8bf2c98d2e62d95c8f86d41895f4cfaca3371d68 (commit)
       via  12dba9fb977f4ca3e62da1f0e29739ca5a534ea8 (commit)
      from  52a60eb5c950491c450ec933f66a56318b4da669 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 807cc540e16eedd53d714a4d9b61a2c24ae31c30
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Dec 10 11:52:00 2012 +0100

    [2445] Some more cleanups
    
    - renamed test class
    - added a subclass of BufferAppender to directly test append()
    (and re-enabled the relevant test case)
    - minor doxy updates

commit 2a69f5cd6a1badf9fb1538cd8f1ca56cef054ba7
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Dec 10 11:26:41 2012 +0100

    [2445] Add assert() after dynamic_cast

commit 7e30c020cd6c0babcf1d2c426ce72eb6a83a7fe4
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Dec 10 11:26:16 2012 +0100

    [2445] rename unit test file as well

commit 17fb43189b8e6a8defa8f6e0a01b13d8ded65d16
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Dec 10 11:24:02 2012 +0100

    [2445] Store string version of log level in buffer
    
    And use those in the case of flushStdout() upon destruction

commit 8bf2c98d2e62d95c8f86d41895f4cfaca3371d68
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Dec 10 10:54:12 2012 +0100

    [2445] rename log_buffer_impl to buffer_appender_impl
    
    Since LogBuffer no longer exists, the file name did not match its content anymore

commit 12dba9fb977f4ca3e62da1f0e29739ca5a534ea8
Author: Jelte Jansen <jelte at isc.org>
Date:   Mon Dec 10 10:31:47 2012 +0100

    [2445] Remove LogBuffer class
    
    and pull its functionality into BufferAppender
    (one unit test temporarily disabled, might be removed in next commit or updated to get around the protected method it uses)

-----------------------------------------------------------------------

Summary of changes:
 src/lib/log/Makefile.am                            |    2 +-
 ...{log_buffer_impl.cc => buffer_appender_impl.cc} |   59 ++++++-----
 .../{log_buffer_impl.h => buffer_appender_impl.h}  |  104 ++++++++------------
 src/lib/log/logger_manager_impl.cc                 |    5 +-
 src/lib/log/tests/Makefile.am                      |    2 +-
 ...fer_unittest.cc => buffer_appender_unittest.cc} |   65 ++++++------
 src/lib/log/tests/buffer_logger_test.sh.in         |    6 +-
 7 files changed, 113 insertions(+), 130 deletions(-)
 rename src/lib/log/{log_buffer_impl.cc => buffer_appender_impl.cc} (69%)
 rename src/lib/log/{log_buffer_impl.h => buffer_appender_impl.h} (54%)
 rename src/lib/log/tests/{log_buffer_unittest.cc => buffer_appender_unittest.cc} (70%)

-----------------------------------------------------------------------
diff --git a/src/lib/log/Makefile.am b/src/lib/log/Makefile.am
index e9074f8..56918e9 100644
--- a/src/lib/log/Makefile.am
+++ b/src/lib/log/Makefile.am
@@ -31,7 +31,7 @@ libb10_log_la_SOURCES += message_initializer.cc message_initializer.h
 libb10_log_la_SOURCES += message_reader.cc message_reader.h
 libb10_log_la_SOURCES += message_types.h
 libb10_log_la_SOURCES += output_option.cc output_option.h
-libb10_log_la_SOURCES += log_buffer_impl.cc log_buffer_impl.h
+libb10_log_la_SOURCES += buffer_appender_impl.cc buffer_appender_impl.h
 
 EXTRA_DIST  = README
 EXTRA_DIST += logimpl_messages.mes
diff --git a/src/lib/log/buffer_appender_impl.cc b/src/lib/log/buffer_appender_impl.cc
new file mode 100644
index 0000000..059500c
--- /dev/null
+++ b/src/lib/log/buffer_appender_impl.cc
@@ -0,0 +1,96 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <log/buffer_appender_impl.h>
+
+#include <log4cplus/loglevel.h>
+#include <boost/scoped_ptr.hpp>
+#include <cstdio>
+
+namespace isc {
+namespace log {
+namespace internal {
+
+BufferAppender::~BufferAppender() {
+    // If there is anything left in the buffer,
+    // it means no reconfig has been done, and
+    // we can assume the logging system was either
+    // never setup, or broke while doing so.
+    // So dump all that is left to stdout
+    try {
+        flushStdout();
+    } catch (...) {
+        // Ok if we can't even seem to dump to stdout, never mind.
+    }
+}
+
+void
+BufferAppender::flushStdout() {
+    // This does not show a bit of information normal log messages
+    // do, so perhaps we should try and setup a new logger here
+    // However, as this is called from a destructor, it may not
+    // be a good idea; as we can't reliably know whether in what
+    // state the logger instance is now (or what the specific logger's
+    // settings were).
+    LogEventList::iterator it;
+    for (it = stored_.begin(); it != stored_.end(); ++it) {
+        const std::string level(it->first);
+        LogEventPtr event(it->second);
+        std::printf("%s [%s]: %s\n", level.c_str(),
+                    event->getLoggerName().c_str(),
+                    event->getMessage().c_str());
+    }
+    stored_.clear();
+}
+
+void
+BufferAppender::flush() {
+    LogEventList stored_copy;
+    stored_.swap(stored_copy);
+
+    LogEventList::const_iterator it;
+    for (it = stored_copy.begin(); it != stored_copy.end(); ++it) {
+        LogEventPtr event(it->second);
+        log4cplus::Logger logger =
+            log4cplus::Logger::getInstance(event->getLoggerName());
+
+        logger.log(event->getLogLevel(), event->getMessage());
+    }
+    flushed_ = true;
+}
+
+size_t
+BufferAppender::getBufferSize() const {
+    return (stored_.size());
+}
+
+void
+BufferAppender::append(const log4cplus::spi::InternalLoggingEvent& event) {
+    if (flushed_) {
+        isc_throw(LogBufferAddAfterFlush,
+                  "Internal log buffer has been flushed already");
+    }
+    // get a clone, and put the pointer in a shared_ptr in the list
+    std::auto_ptr<log4cplus::spi::InternalLoggingEvent> event_aptr =
+        event.clone();
+    // Also store the string representation of the log level, to be
+    // used in flushStdout if necessary
+    stored_.push_back(LevelAndEvent(
+                log4cplus::LogLevelManager().toString(event.getLogLevel()),
+                LogEventPtr(event_aptr.release())));
+}
+
+} // end namespace internal
+} // end namespace log
+} // end namespace isc
diff --git a/src/lib/log/buffer_appender_impl.h b/src/lib/log/buffer_appender_impl.h
new file mode 100644
index 0000000..00d3633
--- /dev/null
+++ b/src/lib/log/buffer_appender_impl.h
@@ -0,0 +1,118 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef LOG_BUFFER_H
+#define LOG_BUFFER_H
+
+#include <exceptions/exceptions.h>
+
+#include <log4cplus/logger.h>
+#include <log4cplus/spi/loggingevent.h>
+#include <boost/shared_ptr.hpp>
+
+namespace isc {
+namespace log {
+namespace internal {
+
+/// \brief Buffer add after flush
+///
+/// This exception is thrown if the log buffer's add() method
+/// is called after the log buffer has been flushed; the buffer
+/// is only supposed to be used once (until the first time a
+/// logger specification is processed)
+class LogBufferAddAfterFlush : public isc::Exception {
+public:
+    LogBufferAddAfterFlush(const char* file, size_t line, const char* what) :
+        isc::Exception(file, line, what)
+    {}
+};
+
+/// Convenience typedef for a pointer to a log event
+typedef boost::shared_ptr<log4cplus::spi::InternalLoggingEvent> LogEventPtr;
+
+/// Convenience typedef for a pair string/logeventptr, the string representing
+/// the logger level, as returned by LogLevelManager::toString() at the
+/// time of initial logging
+typedef std::pair<std::string, LogEventPtr> LevelAndEvent;
+
+/// Convenience typedef for a vector of LevelAndEvent instances
+typedef std::vector<LevelAndEvent> LogEventList;
+
+/// \brief Buffering Logger Appender
+///
+/// This class can be set as an Appender for log4cplus loggers,
+/// and is used to store logging events; it simply keeps any
+/// event that is passed to \c append(), and will replay them to the
+/// logger that they were originally created for when \c flush() is
+/// called.
+///
+/// The idea is that initially, a program may want to do some logging,
+/// but does not know where to yet (for instance because it has yet to
+/// read and parse its configuration). Any log messages before this time
+/// would normally go to some default (say, stdout), and be lost in the
+/// real logging destination. By buffering them (and flushing them once
+/// the logger has been configured), these log messages are kept in a
+/// consistent place, and are not lost.
+///
+/// Given this goal, this class has an extra check; it will raise
+/// an exception if \c append() is called after flush().
+///
+/// If the BufferAppender instance is destroyed before being flushed,
+/// it will dump any event it has left to stdout.
+class BufferAppender : public log4cplus::Appender {
+public:
+    /// \brief Constructor
+    ///
+    /// Constructs a BufferAppender that buffers log evens
+    BufferAppender() : flushed_(false) {}
+
+    /// \brief Destructor
+    ///
+    /// Any remaining events are flushed to stdout (there should
+    /// only be any events remaining if flush() was never called)
+    virtual ~BufferAppender();
+
+    /// \brief Close the appender
+    ///
+    /// This class has no specialized handling for this method
+    virtual void close() {}
+
+    /// \brief Flush the internal buffer
+    ///
+    /// Events that have been stored (after calls to \c append()
+    /// are replayed to the logger. Should only be called after
+    /// new appenders have been set to the logger.
+    void flush();
+
+    /// \brief Returns the number of stored logging events
+    ///
+    /// Mainly useful for testing
+    size_t getBufferSize() const;
+
+protected:
+    virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
+private:
+    /// \brief Helper for the destructor, flush events to stdout
+    void flushStdout();
+
+    LogEventList stored_;
+    bool flushed_;
+};
+
+} // end namespace internal
+} // end namespace log
+} // end namespace isc
+
+#endif // LOG_BUFFER_H
+
diff --git a/src/lib/log/log_buffer_impl.cc b/src/lib/log/log_buffer_impl.cc
deleted file mode 100644
index 05cfe3c..0000000
--- a/src/lib/log/log_buffer_impl.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include <log/log_buffer_impl.h>
-
-#include <log4cplus/loglevel.h>
-#include <boost/scoped_ptr.hpp>
-#include <cstdio>
-
-namespace isc {
-namespace log {
-namespace internal {
-
-LogBuffer::~LogBuffer() {
-    // If there is anything left in the buffer,
-    // it means no reconfig has been done, and
-    // we can assume the logging system was either
-    // never setup, or broke while doing so.
-    // So dump all that is left to stdout
-    try {
-        flushStdout();
-    } catch (...) {
-        // Ok if we can't even seem to dump to stdout, never mind.
-    }
-}
-
-void
-LogBuffer::add(const log4cplus::spi::InternalLoggingEvent& event) {
-    if (flushed_) {
-        isc_throw(LogBufferAddAfterFlush,
-                  "Internal log buffer has been flushed already");
-    }
-    // get a clone, and put the pointer in a shared_pt
-    std::auto_ptr<log4cplus::spi::InternalLoggingEvent> event_aptr =
-        event.clone();
-    boost::shared_ptr<log4cplus::spi::InternalLoggingEvent> event_sptr(
-        event_aptr.release());
-    stored_.push_back(event_sptr);
-}
-
-void
-LogBuffer::flushStdout() {
-    // This does not show a bit of information normal log messages
-    // do, so perhaps we should try and setup a new logger here
-    // However, as this is called from a destructor, it may not
-    // be a good idea; as we can't reliably know whether in what
-    // state the logger instance is now (or what the specific logger's
-    // settings were).
-    // So we print a raw format (it excludes the time and the pid, and
-    // it prints severity as a number)
-    LoggerEventPtrList::const_iterator it;
-    for (it = stored_.begin(); it != stored_.end(); ++it) {
-        std::printf("Severity=%d [%s]: %s\n", (*it)->getLogLevel(),
-                    (*it)->getLoggerName().c_str(),
-                    (*it)->getMessage().c_str());
-    }
-    stored_.clear();
-}
-
-void
-LogBuffer::flush() {
-    LoggerEventPtrList stored_copy;
-    stored_.swap(stored_copy);
-
-    LoggerEventPtrList::const_iterator it;
-    for (it = stored_copy.begin(); it != stored_copy.end(); ++it) {
-        log4cplus::Logger logger =
-            log4cplus::Logger::getInstance((*it)->getLoggerName());
-
-        logger.log((*it)->getLogLevel(), (*it)->getMessage());
-    }
-    stored_.clear();
-    flushed_ = true;
-}
-
-size_t
-LogBuffer::getBufferSize() const {
-    return (stored_.size());
-}
-
-void
-BufferAppender::append(const log4cplus::spi::InternalLoggingEvent& event) {
-    buffer_.add(event);
-}
-
-} // end namespace internal
-} // end namespace log
-} // end namespace isc
diff --git a/src/lib/log/log_buffer_impl.h b/src/lib/log/log_buffer_impl.h
deleted file mode 100644
index e18550a..0000000
--- a/src/lib/log/log_buffer_impl.h
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#ifndef LOG_BUFFER_H
-#define LOG_BUFFER_H
-
-#include <exceptions/exceptions.h>
-
-#include <log4cplus/logger.h>
-#include <log4cplus/spi/loggingevent.h>
-#include <boost/shared_ptr.hpp>
-
-namespace isc {
-namespace log {
-namespace internal {
-
-/// \brief Buffer add after flush
-///
-/// This exception is thrown if the log buffer's add() method
-/// is called after the log buffer has been flushed; the buffer
-/// is only supposed to be used once (until the first time a
-/// logger specification is processed)
-class LogBufferAddAfterFlush : public isc::Exception {
-public:
-    LogBufferAddAfterFlush(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what)
-    {}
-};
-
-/// Convenience typedef for a list of logger events
-typedef std::vector<boost::shared_ptr<log4cplus::spi::InternalLoggingEvent> >
-    LoggerEventPtrList;
-
-/// \brief Buffering class for logging event
-///
-/// This class is used to store logging events; it simply keeps any
-/// event that is passed to \c add(), and will replay them to the
-/// logger that they were originally created for when \c flush() is
-/// called.
-///
-/// The idea is that initially, a program may want to do some logging,
-/// but does not know where to yet (for instance because it has yet to
-/// read and parse its configuration). Any log messages before this time
-/// would normally go to some default (say, stdout), and be lost in the
-/// real logging destination. By buffering them (and flushing them once
-/// the logger has been configured), these log messages are kept in a
-/// consistent place, and are not lost.
-///
-/// Given this goal, this class has an extra check; it will raise
-/// an exception if \c add() is called after flush().
-///
-/// If the LogBuffer instance is destroyed before being flushed, it will
-/// dump any event it has left to stdout.
-class LogBuffer {
-
-public:
-    LogBuffer() : flushed_(false) {};
-
-    ~LogBuffer();
-
-    /// \brief add the given event to the list of stored events
-    ///
-    /// This is called by the BufferAppender.
-    ///
-    /// \param event The event to store
-    /// \exception LogBufferAddAfterFlush if this method is called
-    ///            when \c flush() has been called previously
-    void add(const log4cplus::spi::InternalLoggingEvent& event);
-
-    /// \brief Flush all stored events to their loggers
-    ///
-    /// All events are replayed to their loggers (which should have
-    /// other appenders when this is called.
-    /// Once this method has been called, no more events can be
-    /// added through calls to \c add(); if \c add() is called after flush(),
-    /// an exception will be raised.
-    /// If flush for any reason fails, the remaining events are dropped.
-    void flush();
-
-    /// \brief Returns number of stored events
-    ///
-    /// Mostly for testing purposes
-    size_t getBufferSize() const;
-private:
-    /// \brief Simplified flush() to stdout
-    ///
-    /// Used in the desctructor; all remainging stored events are
-    /// printed to stdout, in case flush() was never called.
-    void flushStdout();
-    LoggerEventPtrList stored_;
-    bool flushed_;
-};
-
-/// \brief Log4cplus appender for our buffer
-///
-/// This class can be set as an Appender for log4cplus loggers
-///
-/// When logging an event, it will not actually log anything, but
-/// merely add it to its internal LogBuffer
-class BufferAppender : public log4cplus::Appender {
-public:
-    /// \brief Constructor
-    ///
-    /// Constructs a BufferAppender with its own LogBuffer instance
-    BufferAppender() {}
-    virtual void close() {}
-
-    /// \brief Flush the internal buffer
-    void flush() {
-        buffer_.flush();
-    }
-
-    /// \brief Access to the internal log buffer
-    ///
-    /// This is mostly for testing
-    LogBuffer& getLogBuffer() {
-        return (buffer_);
-    }
-
-protected:
-    virtual void append(const log4cplus::spi::InternalLoggingEvent& event);
-private:
-    LogBuffer buffer_;
-};
-
-} // end namespace internal
-} // end namespace log
-} // end namespace isc
-
-#endif // LOG_BUFFER_H
-
diff --git a/src/lib/log/logger_manager_impl.cc b/src/lib/log/logger_manager_impl.cc
index 4283cdc..6862d0c 100644
--- a/src/lib/log/logger_manager_impl.cc
+++ b/src/lib/log/logger_manager_impl.cc
@@ -30,7 +30,7 @@
 #include <log/log_messages.h>
 #include <log/logger_name.h>
 #include <log/logger_specification.h>
-#include <log/log_buffer_impl.h>
+#include <log/buffer_appender_impl.h>
 
 using namespace std;
 
@@ -50,7 +50,7 @@ LoggerManagerImpl::processInit() {
     initRootLogger();
 }
 
-// Flush the LogBuffer at the end of processing a new specification
+// Flush the BufferAppenders at the end of processing a new specification
 void
 LoggerManagerImpl::processEnd() {
     flushBufferAppenders();
@@ -262,6 +262,7 @@ void LoggerManagerImpl::flushBufferAppenders() {
     for (it = copy.begin(); it != copy.end(); ++it) {
         internal::BufferAppender* app =
             dynamic_cast<internal::BufferAppender*>(it->get());
+        assert(app != NULL);
         app->flush();
     }
 }
diff --git a/src/lib/log/tests/Makefile.am b/src/lib/log/tests/Makefile.am
index c920735..5683842 100644
--- a/src/lib/log/tests/Makefile.am
+++ b/src/lib/log/tests/Makefile.am
@@ -91,7 +91,7 @@ run_unittests_SOURCES += logger_specification_unittest.cc
 run_unittests_SOURCES += message_dictionary_unittest.cc
 run_unittests_SOURCES += message_reader_unittest.cc
 run_unittests_SOURCES += output_option_unittest.cc
-run_unittests_SOURCES += log_buffer_unittest.cc
+run_unittests_SOURCES += buffer_appender_unittest.cc
 nodist_run_unittests_SOURCES = log_test_messages.cc log_test_messages.h
 
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/src/lib/log/tests/buffer_appender_unittest.cc b/src/lib/log/tests/buffer_appender_unittest.cc
new file mode 100644
index 0000000..78367ca
--- /dev/null
+++ b/src/lib/log/tests/buffer_appender_unittest.cc
@@ -0,0 +1,146 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include "config.h"
+#include <gtest/gtest.h>
+
+#include <log/macros.h>
+#include <log/logger_support.h>
+#include <log/log_messages.h>
+#include <log/buffer_appender_impl.h>
+
+#include <log4cplus/loggingmacros.h>
+#include <log4cplus/logger.h>
+#include <log4cplus/nullappender.h>
+#include <log4cplus/spi/loggingevent.h>
+
+using namespace isc::log;
+using namespace isc::log::internal;
+
+namespace isc {
+namespace log {
+
+/// \brief Specialized test class
+///
+/// In order to test append() somewhat directly, this
+/// class implements one more method (addEvent)
+class TestBufferAppender : public BufferAppender {
+public:
+    void addEvent(const log4cplus::spi::InternalLoggingEvent& event) {
+        append(event);
+    }
+};
+
+class BufferAppenderTest : public ::testing::Test {
+protected:
+    BufferAppenderTest() : buffer_appender1(new TestBufferAppender()),
+                      buffer_appender2(new TestBufferAppender()),
+                      appender1(buffer_appender1),
+                      appender2(buffer_appender2),
+                      logger(log4cplus::Logger::getInstance("buffer"))
+    {
+        logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL);
+    }
+
+    ~BufferAppenderTest() {
+        // If any log messages are left, we don't care, get rid of them,
+        // by flushing them to a null appender
+        // Given the 'messages should not get lost' approach of the logging
+        // system, not flushing them to a null appender would cause them
+        // to be dumped to stdout as the test is destroyed, making
+        // unnecessarily messy test output.
+        log4cplus::SharedAppenderPtr null_appender(
+            new log4cplus::NullAppender());
+        logger.removeAllAppenders();
+        logger.addAppender(null_appender);
+        buffer_appender1->flush();
+        buffer_appender2->flush();
+    }
+
+    TestBufferAppender* buffer_appender1;
+    TestBufferAppender* buffer_appender2;
+    log4cplus::SharedAppenderPtr appender1;
+    log4cplus::SharedAppenderPtr appender2;
+    log4cplus::Logger logger;
+};
+
+// Test that log events are indeed stored, and that they are
+// flushed to the new appenders of their logger
+TEST_F(BufferAppenderTest, flush) {
+    ASSERT_EQ(0, buffer_appender1->getBufferSize());
+    ASSERT_EQ(0, buffer_appender2->getBufferSize());
+
+    // Create a Logger, log a few messages with the first appender
+    logger.addAppender(appender1);
+    LOG4CPLUS_INFO(logger, "Foo");
+    ASSERT_EQ(1, buffer_appender1->getBufferSize());
+    LOG4CPLUS_INFO(logger, "Foo");
+    ASSERT_EQ(2, buffer_appender1->getBufferSize());
+    LOG4CPLUS_INFO(logger, "Foo");
+    ASSERT_EQ(3, buffer_appender1->getBufferSize());
+
+    // Second buffer should still be empty
+    ASSERT_EQ(0, buffer_appender2->getBufferSize());
+
+    // Replace the appender by the second one, and call flush;
+    // this should cause all events to be moved to the second buffer
+    logger.removeAllAppenders();
+    logger.addAppender(appender2);
+    buffer_appender1->flush();
+    ASSERT_EQ(0, buffer_appender1->getBufferSize());
+    ASSERT_EQ(3, buffer_appender2->getBufferSize());
+}
+
+// Once flushed, logging new messages with the same buffer should fail
+TEST_F(BufferAppenderTest, addAfterFlush) {
+    logger.addAppender(appender1);
+    buffer_appender1->flush();
+    EXPECT_THROW(LOG4CPLUS_INFO(logger, "Foo"), LogBufferAddAfterFlush);
+    // It should not have been added
+    ASSERT_EQ(0, buffer_appender1->getBufferSize());
+
+    // But logging should work again as long as a different buffer is used
+    logger.removeAllAppenders();
+    logger.addAppender(appender2);
+    LOG4CPLUS_INFO(logger, "Foo");
+    ASSERT_EQ(1, buffer_appender2->getBufferSize());
+}
+
+TEST_F(BufferAppenderTest, addDirectly) {
+    // A few direct calls
+    log4cplus::spi::InternalLoggingEvent event("buffer",
+                                               log4cplus::INFO_LOG_LEVEL,
+                                               "Bar", "file", 123);
+    buffer_appender1->addEvent(event);
+    ASSERT_EQ(1, buffer_appender1->getBufferSize());
+
+    // Do one from a smaller scope to make sure destruction doesn't harm
+    {
+        log4cplus::spi::InternalLoggingEvent event2("buffer",
+                                                    log4cplus::INFO_LOG_LEVEL,
+                                                    "Bar", "file", 123);
+        buffer_appender1->addEvent(event2);
+    }
+    ASSERT_EQ(2, buffer_appender1->getBufferSize());
+
+    // And flush them to the next
+    logger.removeAllAppenders();
+    logger.addAppender(appender2);
+    buffer_appender1->flush();
+    ASSERT_EQ(0, buffer_appender1->getBufferSize());
+    ASSERT_EQ(2, buffer_appender2->getBufferSize());
+}
+
+}
+}
diff --git a/src/lib/log/tests/buffer_logger_test.sh.in b/src/lib/log/tests/buffer_logger_test.sh.in
index 5fbdc62..696f829 100755
--- a/src/lib/log/tests/buffer_logger_test.sh.in
+++ b/src/lib/log/tests/buffer_logger_test.sh.in
@@ -46,9 +46,9 @@ passfail $?
 
 echo -n  "   - Buffer excluding process() call: "
 cat > $tempfile << .
-Severity=20000 [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
-Severity=10000 [buffertest.log]: LOG_BAD_DESTINATION unrecognized log destination: debug-50
-Severity=20000 [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
+INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
+DEBUG [buffertest.log]: LOG_BAD_DESTINATION unrecognized log destination: debug-50
+INFO [buffertest.log]: LOG_BAD_SEVERITY unrecognized log severity: info
 .
 ./buffer_logger_test -n 2>&1 | diff $tempfile -
 passfail $?
diff --git a/src/lib/log/tests/log_buffer_unittest.cc b/src/lib/log/tests/log_buffer_unittest.cc
deleted file mode 100644
index cf33b60..0000000
--- a/src/lib/log/tests/log_buffer_unittest.cc
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-//
-// Permission to use, copy, modify, and/or distribute this software for any
-// purpose with or without fee is hereby granted, provided that the above
-// copyright notice and this permission notice appear in all copies.
-//
-// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
-// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-// PERFORMANCE OF THIS SOFTWARE.
-
-#include "config.h"
-#include <gtest/gtest.h>
-
-#include <log/macros.h>
-#include <log/logger_support.h>
-#include <log/log_messages.h>
-#include <log/log_buffer_impl.h>
-
-#include <log4cplus/loggingmacros.h>
-#include <log4cplus/logger.h>
-#include <log4cplus/nullappender.h>
-#include <log4cplus/spi/loggingevent.h>
-
-using namespace isc::log;
-using namespace isc::log::internal;
-
-namespace isc {
-namespace log {
-
-class LogBufferTest : public ::testing::Test {
-protected:
-    LogBufferTest() : buffer_appender1(new BufferAppender()),
-                      buffer_appender2(new BufferAppender()),
-                      appender1(buffer_appender1),
-                      appender2(buffer_appender2),
-                      logger(log4cplus::Logger::getInstance("buffer"))
-    {
-        logger.setLogLevel(log4cplus::TRACE_LOG_LEVEL);
-    }
-
-    ~LogBufferTest() {
-        // If any log messages are left, we don't care, get rid of them,
-        // by flushing them to a null appender
-        // Given the 'messages should not get lost' approach of the logging
-        // system, not flushing them to a null appender would cause them
-        // to be dumped to stdout as the test is destroyed, making
-        // unnecessarily messy test output.
-        log4cplus::SharedAppenderPtr null_appender(
-            new log4cplus::NullAppender());
-        logger.removeAllAppenders();
-        logger.addAppender(null_appender);
-        buffer_appender1->flush();
-        buffer_appender2->flush();
-    }
-
-    //LogBuffer buffer_appender1->getLogBuffer().
-    //LogBuffer buffer_appender2->getLogBuffer().
-    BufferAppender* buffer_appender1;
-    BufferAppender* buffer_appender2;
-    log4cplus::SharedAppenderPtr appender1;
-    log4cplus::SharedAppenderPtr appender2;
-    log4cplus::Logger logger;
-};
-
-// Test that log events are indeed stored, and that they are
-// flushed to the new appenders of their logger
-TEST_F(LogBufferTest, flush) {
-    ASSERT_EQ(0, buffer_appender1->getLogBuffer().getBufferSize());
-    ASSERT_EQ(0, buffer_appender2->getLogBuffer().getBufferSize());
-
-    // Create a Logger, log a few messages with the first appender
-    logger.addAppender(appender1);
-    LOG4CPLUS_INFO(logger, "Foo");
-    ASSERT_EQ(1, buffer_appender1->getLogBuffer().getBufferSize());
-    LOG4CPLUS_INFO(logger, "Foo");
-    ASSERT_EQ(2, buffer_appender1->getLogBuffer().getBufferSize());
-    LOG4CPLUS_INFO(logger, "Foo");
-    ASSERT_EQ(3, buffer_appender1->getLogBuffer().getBufferSize());
-
-    // Second buffer should still be empty
-    ASSERT_EQ(0, buffer_appender2->getLogBuffer().getBufferSize());
-
-    // Replace the appender by the second one, and call flush;
-    // this should cause all events to be moved to the second buffer
-    logger.removeAllAppenders();
-    logger.addAppender(appender2);
-    buffer_appender1->flush();
-    ASSERT_EQ(0, buffer_appender1->getLogBuffer().getBufferSize());
-    ASSERT_EQ(3, buffer_appender2->getLogBuffer().getBufferSize());
-}
-
-// Once flushed, logging new messages with the same buffer should fail
-TEST_F(LogBufferTest, addAfterFlush) {
-    logger.addAppender(appender1);
-    buffer_appender1->flush();
-    EXPECT_THROW(LOG4CPLUS_INFO(logger, "Foo"), LogBufferAddAfterFlush);
-    // It should not have been added
-    ASSERT_EQ(0, buffer_appender1->getLogBuffer().getBufferSize());
-
-    // But logging should work again as long as a different buffer is used
-    logger.removeAllAppenders();
-    logger.addAppender(appender2);
-    LOG4CPLUS_INFO(logger, "Foo");
-    ASSERT_EQ(1, buffer_appender2->getLogBuffer().getBufferSize());
-}
-
-TEST_F(LogBufferTest, addDirectly) {
-    // A few direct calls
-    log4cplus::spi::InternalLoggingEvent event("buffer",
-                                               log4cplus::INFO_LOG_LEVEL,
-                                               "Bar", "file", 123);
-    buffer_appender1->getLogBuffer().add(event);
-    ASSERT_EQ(1, buffer_appender1->getLogBuffer().getBufferSize());
-
-    // Do one from a smaller scope to make sure destruction doesn't harm
-    {
-        log4cplus::spi::InternalLoggingEvent event2("buffer",
-                                                    log4cplus::INFO_LOG_LEVEL,
-                                                    "Bar", "file", 123);
-        buffer_appender1->getLogBuffer().add(event2);
-    }
-    ASSERT_EQ(2, buffer_appender1->getLogBuffer().getBufferSize());
-
-    // And flush them to the next
-    logger.removeAllAppenders();
-    logger.addAppender(appender2);
-    buffer_appender1->flush();
-    ASSERT_EQ(0, buffer_appender1->getLogBuffer().getBufferSize());
-    ASSERT_EQ(2, buffer_appender2->getLogBuffer().getBufferSize());
-}
-
-}
-}



More information about the bind10-changes mailing list