Commit ff5fac04 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix double-logging in daemons

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
parent c89189b1
......@@ -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")
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment