BIND 10 trac555, updated. 3d05a83e9466e6075dec6e4b7a1502989d9205e9 [trac555] Add file appender

BIND 10 source code commits bind10-changes at lists.isc.org
Thu May 26 15:54:53 UTC 2011


The branch, trac555 has been updated
       via  3d05a83e9466e6075dec6e4b7a1502989d9205e9 (commit)
      from  acfbd3b209c50aeff46fc09f9d792a457f51722d (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 3d05a83e9466e6075dec6e4b7a1502989d9205e9
Author: Stephen Morris <stephen at isc.org>
Date:   Thu May 26 16:53:46 2011 +0100

    [trac555] Add file appender
    
    Added the file appender, which routes output to a file (appending
    to a file if one exists).

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

Summary of changes:
 src/lib/log/logger_manager.cc                |    6 +++++-
 src/lib/log/logger_manager_impl.cc           |   25 +++++++++++++++++++++++++
 src/lib/log/logger_manager_impl.h            |    2 +-
 src/lib/log/tests/logger_manager_unittest.cc |    3 ---
 src/lib/log/tests/logger_support_test.cc     |   26 +++++++++++++++++++++-----
 5 files changed, 52 insertions(+), 10 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/log/logger_manager.cc b/src/lib/log/logger_manager.cc
index c89a46b..71c26af 100644
--- a/src/lib/log/logger_manager.cc
+++ b/src/lib/log/logger_manager.cc
@@ -105,6 +105,8 @@ LoggerManager::init(const std::string& root, const char* file,
 
 
 /// Read local message file
+// TODO This should be done after the configuration has been read so that
+// the file can be placed in the local configuration
 void
 LoggerManager::readLocalMessageFile(const char* file) {
 
@@ -113,7 +115,9 @@ LoggerManager::readLocalMessageFile(const char* file) {
     MessageDictionary& dictionary = MessageDictionary::globalDictionary();
     MessageReader reader(&dictionary);
     try {
-        logger.info(MSG_RDLOCMES).arg(file);
+
+        // FIXEM: commented out for testing
+        // logger.info(MSG_RDLOCMES).arg(file);
         reader.readFile(file, MessageReader::REPLACE);
 
         // File successfully read, list the duplicates
diff --git a/src/lib/log/logger_manager_impl.cc b/src/lib/log/logger_manager_impl.cc
index 29e9339..46886b0 100644
--- a/src/lib/log/logger_manager_impl.cc
+++ b/src/lib/log/logger_manager_impl.cc
@@ -17,6 +17,7 @@
 #include <log4cplus/logger.h>
 #include <log4cplus/configurator.h>
 #include <log4cplus/consoleappender.h>
+#include <log4cplus/fileappender.h>
 
 #include "log/logger_level_impl.h"
 #include "log/logger_manager_impl.h"
@@ -119,6 +120,30 @@ LoggerManagerImpl::createConsoleAppender(log4cplus::Logger& logger,
     logger.addAppender(console);
 }
 
+// File appender.  Depending on whether a maximum size is given, either
+// a standard file appender or a rolling file appender will be created.
+void
+LoggerManagerImpl::createFileAppender(log4cplus::Logger& logger,
+                                         const OutputOption& opt)
+{
+    LOG4CPLUS_OPEN_MODE_TYPE mode = 
+        LOG4CPLUS_FSTREAM_NAMESPACE::ios::app;  // Append to existing file
+
+    log4cplus::SharedAppenderPtr fileapp;
+    if (opt.maxsize == 0) {
+        fileapp = log4cplus::SharedAppenderPtr(new log4cplus::FileAppender(
+            opt.filename, mode, opt.flush));
+    } else {
+        fileapp = log4cplus::SharedAppenderPtr(
+            new log4cplus::RollingFileAppender(opt.filename, opt.maxsize,
+                                               opt.maxver, opt.flush));
+    }
+
+    // use the same console layout for the files.
+    setConsoleAppenderLayout(fileapp);
+    logger.addAppender(fileapp);
+}
+
 
 // One-time initialization of the log4cplus system
 
diff --git a/src/lib/log/logger_manager_impl.h b/src/lib/log/logger_manager_impl.h
index 6dc488c..706d5e0 100644
--- a/src/lib/log/logger_manager_impl.h
+++ b/src/lib/log/logger_manager_impl.h
@@ -101,7 +101,7 @@ private:
     /// \param logger Log4cplus logger to which the appender must be attached.
     /// \param opt Output options for this appender.
     void createFileAppender(log4cplus::Logger& logger,
-                            const OutputOption& opt) {}
+                            const OutputOption& opt);
 
     /// \brief Create syslog appender
     ///
diff --git a/src/lib/log/tests/logger_manager_unittest.cc b/src/lib/log/tests/logger_manager_unittest.cc
index 3b65c38..54dc130 100644
--- a/src/lib/log/tests/logger_manager_unittest.cc
+++ b/src/lib/log/tests/logger_manager_unittest.cc
@@ -131,15 +131,12 @@ public:
         }
         filename << "/bind10_logger_manager_test_XXXXXX";
 
-        cout << "*** file name before call is " << filename.str() << "\n";
-
         // Copy into writeable storage for the call to mkstemp
         boost::scoped_array<char> tname(new char[filename.str().size() + 1]);
         strcpy(tname.get(), filename.str().c_str());
 
         // Create file, close and delete it, and store the name for later.
         int filenum = mkstemp(tname.get());
-        cout << "*** file name after call is " << tname.get() << "\n";
         if (filenum == -1) {
             isc_throw(Exception, "Unable to obtain unique filename");
         }
diff --git a/src/lib/log/tests/logger_support_test.cc b/src/lib/log/tests/logger_support_test.cc
index 649f4c6..3a2b11a 100644
--- a/src/lib/log/tests/logger_support_test.cc
+++ b/src/lib/log/tests/logger_support_test.cc
@@ -42,17 +42,21 @@ using namespace std;
 
 void usage() {
     cout <<
-"logger_support_test [-h] [-s severity] [-d dbglevel] [-c stream] [localfile]\n"
+"logger_support_test [-h] [-c stream] [-d dbglevel] [-f file]\n"
+"                    [-s severity] [localfile]\n"
 "\n"
 "   -h              Print this message and exit\n"
-"   -s severity     Set the severity of messages output.  'severity' is one\n"
-"                   of 'debug', 'info', 'warn', 'error', 'fatal', the default\n"
-"                   being 'info'.\n"
+"\n"
 "   -d dbglevel     Debug level.  Only interpreted if the severity is 'debug'\n"
 "                   this is a number between 0 and 99.\n"
 "   -c stream       Send output to the console.  'stream' is one of 'stdout'\n"
 "                   of 'stderr'.  The '-c' switch is incompatible with '-f'\n"
 "                   and '-l'\n"
+"   -f file         Send output to specified file, appending to existing file\n"
+"                   if one exists.  Incompatible with -c and -l switches.\n"
+"   -s severity     Set the severity of messages output.  'severity' is one\n"
+"                   of 'debug', 'info', 'warn', 'error', 'fatal', the default\n"
+"                   being 'info'.\n"
 "\n"
 "If none of -c, -f or -l is given, by default, output is sent to stdout\n";
 }
@@ -80,7 +84,7 @@ int main(int argc, char** argv) {
     Logger rootLogger(ROOT_NAME);
 
     // Parse options
-    while ((option = getopt(argc, argv, "hc:d:s:")) != -1) {
+    while ((option = getopt(argc, argv, "hc:d:f:s:")) != -1) {
         switch (option) {
         case 'c':
             if (f_found || l_found) {
@@ -107,6 +111,18 @@ int main(int argc, char** argv) {
             spec.setDbglevel(boost::lexical_cast<int>(optarg));
             break;
 
+        case 'f':
+            if (c_found || l_found) {
+                cerr << "Cannot specify -f with -c or -l\n";
+                return (1);
+            }
+
+            f_found = true;
+
+            outopt.destination = OutputOption::DEST_FILE;
+            outopt.filename = optarg;
+            break;
+
         case 'h':
             usage();
             return (0);




More information about the bind10-changes mailing list