Fix double-logging in daemons
authorIustin Pop <iustin@google.com>
Wed, 9 Jul 2008 14:46:16 +0000 (14:46 +0000)
committerIustin Pop <iustin@google.com>
Wed, 9 Jul 2008 14:46:16 +0000 (14:46 +0000)
Currently, in debug mode, both the logfile handler and the stderr
handler will log debug messages. Since the stderr is redirected to the
same logfile (to catch non-logged errors), it means log entries are
doubled.

The patch adds an extra parameter to the logger.SetupDaemon() function
that allows disabling of the stderr logging. The master and node daemon
will use this to enable stderr logging only when running in foreground.

Reviewed-by: imsnah

daemons/ganeti-masterd
daemons/ganeti-noded
lib/logger.py

index 5c8d116..8e3701c 100755 (executable)
@@ -391,7 +391,8 @@ def main():
     utils.Daemonize(logfile=constants.LOG_MASTERDAEMON,
                     noclose_fds=[master.fileno()])
 
-  logger.SetupDaemon(constants.LOG_MASTERDAEMON, debug=options.debug)
+  logger.SetupDaemon(constants.LOG_MASTERDAEMON, debug=options.debug,
+                     stderr_logging=not options.fork)
 
   logging.info("ganeti master daemon startup")
 
index b5d1984..cb72b4c 100755 (executable)
@@ -633,7 +633,8 @@ def main():
   if options.fork:
     utils.Daemonize(logfile=constants.LOG_NODESERVER)
 
-  logger.SetupDaemon(logfile=constants.LOG_NODESERVER, debug=options.debug)
+  logger.SetupDaemon(logfile=constants.LOG_NODESERVER, debug=options.debug,
+                     stderr_logging=not options.fork)
   logging.info("ganeti node daemon startup")
 
   global _EXIT_GANETI_NODED
index f92dbaa..37573ee 100644 (file)
@@ -84,12 +84,12 @@ def SetupLogging(program='ganeti', debug=False):
   root_logger.addHandler(stderr_file)
 
 
-def SetupDaemon(logfile, debug=False):
+def SetupDaemon(logfile, debug=False, stderr_logging=False):
   """Configures the logging module for daemons
 
   """
   if debug:
-    fmt = "%(asctime)s: %(levelname)s %(pathname)s:%(lineno)s %(message)s"
+    fmt = "%(asctime)s: %(levelname)s %(module)s:%(lineno)s %(message)s"
   else:
     fmt = "%(asctime)s: %(levelname)s %(message)s"
   formatter = logging.Formatter(fmt)
@@ -109,7 +109,8 @@ def SetupDaemon(logfile, debug=False):
   root_logger = logging.getLogger("")
   root_logger.setLevel(logging.NOTSET)
   root_logger.addHandler(logfile_handler)
-  root_logger.addHandler(stderr_handler)
+  if stderr_logging:
+    root_logger.addHandler(stderr_handler)
 
 
 # Backwards compatibility