diff --git a/lib/cli.py b/lib/cli.py index ce97e998a88d59172c7e050ffec9d1750a976fcd..e9576db0e20513913ba6351b43d1e2fe807a340f 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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) diff --git a/lib/daemon.py b/lib/daemon.py index c26a17625d55b8e9f4da2496f9a403b9fb2bc533..6fb2f69955011e67c9c920ebb2d7b361df0cddd6 100644 --- a/lib/daemon.py +++ b/lib/daemon.py @@ -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): diff --git a/lib/utils/log.py b/lib/utils/log.py index f91d44a867baa30c2bcdf3d464d61e1608275c2b..361bd985c73478b4a69b78514f4667c37506e625 100644 --- a/lib/utils/log.py +++ b/lib/utils/log.py @@ -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) diff --git a/lib/watcher/__init__.py b/lib/watcher/__init__.py index 4503c63ae2407f653297bd819e113fa0abd3d1d8..098f8c2d577cf37b83348adb838d6d11f5ff9bfd 100644 --- a/lib/watcher/__init__.py +++ b/lib/watcher/__init__.py @@ -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") diff --git a/tools/burnin b/tools/burnin index b1b0d2bb13ecdeaade1ecb9afd7bf7f96c6ca49c..a47ea19b489f39a66c741d3f8f56b04c6750b229 100755 --- a/tools/burnin +++ b/tools/burnin @@ -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()