Commit cfcc79c6 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

utils.SetupLogging: Make program a mandatory argument



It's passed in by most users (daemons, CLI scripts) and for the others
(burnin, watcher) it certainly doesn't hurt, especially when using
syslog.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent aa0cc3e5
......@@ -1913,8 +1913,8 @@ def GenericMain(commands, override=None, aliases=None):
for key, val in override.iteritems():
setattr(options, key, val)
utils.SetupLogging(constants.LOG_COMMANDS, debug=options.debug,
stderr_logging=True, program=binary)
utils.SetupLogging(constants.LOG_COMMANDS, binary, debug=options.debug,
stderr_logging=True)
if old_cmdline:
logging.info("run with arguments '%s'", old_cmdline)
......
......@@ -659,11 +659,10 @@ def GenericMain(daemon_name, optionparser,
utils.WritePidFile(utils.DaemonPidFileName(daemon_name))
try:
try:
utils.SetupLogging(logfile=constants.DAEMONS_LOGFILES[daemon_name],
utils.SetupLogging(constants.DAEMONS_LOGFILES[daemon_name], daemon_name,
debug=options.debug,
stderr_logging=not options.fork,
multithreaded=multithreaded,
program=daemon_name,
syslog=options.syslog,
console_logging=console_logging)
if callable(prepare_fn):
......
......@@ -22,6 +22,7 @@
"""
import os.path
import logging
import logging.handlers
......@@ -162,20 +163,20 @@ def _GetLogFormatter(program, multithreaded, debug, syslog):
return logging.Formatter("".join(parts))
def SetupLogging(logfile, debug=0, stderr_logging=False, program="",
def SetupLogging(logfile, program, debug=0, stderr_logging=False,
multithreaded=False, syslog=constants.SYSLOG_USAGE,
console_logging=False):
"""Configures the logging module.
@type logfile: str
@param logfile: the filename to which we should log
@type program: str
@param program: the name under which we should log messages
@type debug: integer
@param debug: if greater than zero, enable debug messages, otherwise
only those at C{INFO} and above level
@type stderr_logging: boolean
@param stderr_logging: whether we should also log to the standard error
@type program: str
@param program: the name under which we should log messages
@type multithreaded: boolean
@param multithreaded: if True, will add the thread name to the log file
@type syslog: string
......@@ -190,8 +191,10 @@ def SetupLogging(logfile, debug=0, stderr_logging=False, program="",
syslog/stderr logging is disabled
"""
formatter = _GetLogFormatter(program, multithreaded, debug, False)
syslog_fmt = _GetLogFormatter(program, multithreaded, debug, True)
progname = os.path.basename(program)
formatter = _GetLogFormatter(progname, multithreaded, debug, False)
syslog_fmt = _GetLogFormatter(progname, multithreaded, debug, True)
root_logger = logging.getLogger("")
root_logger.setLevel(logging.NOTSET)
......
......@@ -32,6 +32,7 @@ by a node reboot. Run from cron or similar.
# C0103: Invalid name ganeti-watcher
import os
import os.path
import sys
import time
import logging
......@@ -714,8 +715,8 @@ def Main():
print >> sys.stderr, ("Usage: %s [-f] " % sys.argv[0])
return constants.EXIT_FAILURE
utils.SetupLogging(constants.LOG_WATCHER, debug=options.debug,
stderr_logging=options.debug)
utils.SetupLogging(constants.LOG_WATCHER, sys.argv[0],
debug=options.debug, stderr_logging=options.debug)
if ShouldPause() and not options.ignore_pause:
logging.debug("Pause has been set, exiting")
......
......@@ -1071,7 +1071,8 @@ def main():
"""Main function.
"""
utils.SetupLogging(constants.LOG_BURNIN, debug=False, stderr_logging=True)
utils.SetupLogging(constants.LOG_BURNIN, sys.argv[0],
debug=False, stderr_logging=True)
return Burner().BurninCluster()
......
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