Parcourir la source

[1622] some cleanups

JINMEI Tatuya il y a 12 ans
Parent
commit
c1ca91c677
1 fichiers modifiés avec 7 ajouts et 2 suppressions
  1. 7 2
      src/lib/log/logger_manager_impl.cc

+ 7 - 2
src/lib/log/logger_manager_impl.cc

@@ -124,12 +124,17 @@ LoggerManagerImpl::createConsoleAppender(log4cplus::Logger& logger,
 
 // File appender.  Depending on whether a maximum size is given, either
 // 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
 LoggerManagerImpl::createFileAppender(log4cplus::Logger& logger,
                                       const OutputOption& opt)
 {
     // Append to existing file
-    std::ios::openmode mode = std::ios::app;
+    const std::ios::openmode mode = std::ios::app;
 
     log4cplus::SharedAppenderPtr fileapp;
     if (opt.maxsize == 0) {
@@ -142,7 +147,7 @@ LoggerManagerImpl::createFileAppender(log4cplus::Logger& logger,
                                lexical_cast<string>(opt.maxsize));
         properties.setProperty("MaxBackupIndex",
                                lexical_cast<string>(opt.maxver));
-        properties.setProperty("ImmediateFlush", "true");
+        properties.setProperty("ImmediateFlush", opt.flush ? "true" : "false");
         properties.setProperty("UseLockFile", "true");
         fileapp = log4cplus::SharedAppenderPtr(
             new log4cplus::RollingFileAppender(properties));