Parcourir la source

[master] Merge branch 'trac1622'

JINMEI Tatuya il y a 12 ans
Parent
commit
5da8f8131b

+ 17 - 0
doc/guide/bind10-guide.xml

@@ -5567,6 +5567,23 @@ TODO; there's a ticket to determine these levels, see #1074
             If this is 0, no maximum file size is used.
             If this is 0, no maximum file size is used.
           </para>
           </para>
 
 
+          <note>
+            <simpara>
+	      Due to a limitation of the underlying logging library
+	      (log4cplus), rolling over the log files (from ".1" to
+	      ".2", etc) may show odd results: There can be
+	      multiple small files at the timing of roll over.  This
+	      can happen when multiple BIND 10 processes try to roll
+	      over the files simultaneously.
+	      Version 1.1.0 of log4cplus solved this problem, so if
+	      this or higher version of log4cplus is used to build
+	      BIND 10, it shouldn't happen.  Even for older versions
+	      it is normally expected to happen rarely unless the log
+	      messages are produced very frequently by multiple
+	      different processes.
+	    </simpara>
+	  </note>
+
         </section>
         </section>
 
 
         <section>
         <section>

+ 19 - 4
src/lib/log/logger_manager_impl.cc

@@ -35,7 +35,10 @@
 #include <log/logger_specification.h>
 #include <log/logger_specification.h>
 #include <log/buffer_appender_impl.h>
 #include <log/buffer_appender_impl.h>
 
 
+#include <boost/lexical_cast.hpp>
+
 using namespace std;
 using namespace std;
+using boost::lexical_cast;
 
 
 namespace isc {
 namespace isc {
 namespace log {
 namespace log {
@@ -121,21 +124,33 @@ LoggerManagerImpl::createConsoleAppender(log4cplus::Logger& logger,
 
 
 // File appender.  Depending on whether a maximum size is given, either
 // File appender.  Depending on whether a maximum size is given, either
 // a standard file appender or a rolling file appender will be created.
 // a standard file appender or a rolling file appender will be created.
+// In the case of the latter, we set "UseLockFile" to true so that
+// log4cplus internally avoids race in rolling over the files by multiple
+// processes.  This feature isn't supported in log4cplus 1.0.x, but setting
+// the property unconditionally is okay as unknown properties are simply
+// ignored.
 void
 void
 LoggerManagerImpl::createFileAppender(log4cplus::Logger& logger,
 LoggerManagerImpl::createFileAppender(log4cplus::Logger& logger,
-                                         const OutputOption& opt)
+                                      const OutputOption& opt)
 {
 {
     // Append to existing file
     // Append to existing file
-    std::ios::openmode mode = std::ios::app;
+    const std::ios::openmode mode = std::ios::app;
 
 
     log4cplus::SharedAppenderPtr fileapp;
     log4cplus::SharedAppenderPtr fileapp;
     if (opt.maxsize == 0) {
     if (opt.maxsize == 0) {
         fileapp = log4cplus::SharedAppenderPtr(new log4cplus::FileAppender(
         fileapp = log4cplus::SharedAppenderPtr(new log4cplus::FileAppender(
             opt.filename, mode, opt.flush));
             opt.filename, mode, opt.flush));
     } else {
     } else {
+        log4cplus::helpers::Properties properties;
+        properties.setProperty("File", opt.filename);
+        properties.setProperty("MaxFileSize",
+                               lexical_cast<string>(opt.maxsize));
+        properties.setProperty("MaxBackupIndex",
+                               lexical_cast<string>(opt.maxver));
+        properties.setProperty("ImmediateFlush", opt.flush ? "true" : "false");
+        properties.setProperty("UseLockFile", "true");
         fileapp = log4cplus::SharedAppenderPtr(
         fileapp = log4cplus::SharedAppenderPtr(
-            new log4cplus::RollingFileAppender(opt.filename, opt.maxsize,
-                                               opt.maxver, opt.flush));
+            new log4cplus::RollingFileAppender(properties));
     }
     }
 
 
     // use the same console layout for the files.
     // use the same console layout for the files.

+ 1 - 1
src/lib/log/tests/Makefile.am

@@ -10,7 +10,7 @@ if USE_STATIC_LINK
 AM_LDFLAGS += -static
 AM_LDFLAGS += -static
 endif
 endif
 
 
-CLEANFILES = *.gcno *.gcda
+CLEANFILES = *.gcno *.gcda *.lock
 
 
 EXTRA_DIST = log_test_messages.mes
 EXTRA_DIST = log_test_messages.mes
 BUILT_SOURCES = log_test_messages.h log_test_messages.cc
 BUILT_SOURCES = log_test_messages.h log_test_messages.cc

+ 5 - 1
src/lib/log/tests/logger_manager_unittest.cc

@@ -77,7 +77,11 @@ public:
     // Destructor, remove the file.  This is only a test, so ignore failures
     // Destructor, remove the file.  This is only a test, so ignore failures
     ~SpecificationForFileLogger() {
     ~SpecificationForFileLogger() {
         if (! name_.empty()) {
         if (! name_.empty()) {
-            (void) unlink(name_.c_str());
+            static_cast<void>(unlink(name_.c_str()));
+
+            // Depending on the log4cplus version, a lock file may also be
+            // created.
+            static_cast<void>(unlink((name_ + ".lock").c_str()));
         }
         }
     }
     }