From: Ansgar Burchardt Date: Sat, 14 May 2011 19:58:03 +0000 (+0000) Subject: restore program name to log messages X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7c62d1659a2078584a1158466d4abe13c1f4ff3;p=dak restore program name to log messages --- diff --git a/dak/check_overrides.py b/dak/check_overrides.py index 7c924649..a8e0f1d9 100755 --- a/dak/check_overrides.py +++ b/dak/check_overrides.py @@ -341,9 +341,9 @@ def main (): priorities[entry] = name if not Options["No-Action"]: - Logger = daklog.Logger(cnf, "check-overrides") + Logger = daklog.Logger("check-overrides") else: - Logger = daklog.Logger(cnf, "check-overrides", 1) + Logger = daklog.Logger("check-overrides", 1) for osuite in cnf.SubTree("Check-Overrides::OverrideSuites").List(): if "1" != cnf["Check-Overrides::OverrideSuites::%s::Process" % osuite]: diff --git a/dak/clean_queues.py b/dak/clean_queues.py index f6964508..474fe390 100755 --- a/dak/clean_queues.py +++ b/dak/clean_queues.py @@ -193,7 +193,7 @@ def main (): if Options["Help"]: usage() - Logger = daklog.Logger(cnf, 'clean-queues', Options['No-Action']) + Logger = daklog.Logger('clean-queues', Options['No-Action']) init(cnf) diff --git a/dak/clean_suites.py b/dak/clean_suites.py index ab1e76d7..5e41d372 100755 --- a/dak/clean_suites.py +++ b/dak/clean_suites.py @@ -426,7 +426,7 @@ def main(): if Options["Help"]: usage() - Logger = daklog.Logger(cnf, "clean-suites", debug=Options["No-Action"]) + Logger = daklog.Logger("clean-suites", debug=Options["No-Action"]) session = DBConn().session() diff --git a/dak/contents.py b/dak/contents.py index c2d04eb6..76effc1d 100755 --- a/dak/contents.py +++ b/dak/contents.py @@ -85,14 +85,14 @@ OPTIONS for scan-source and scan-binary ################################################################################ def write_all(cnf, suite_names = [], component_names = [], force = None): - Logger = daklog.Logger(cnf.Cnf, 'contents generate') + Logger = daklog.Logger('contents generate') ContentsWriter.write_all(Logger, suite_names, component_names, force) Logger.close() ################################################################################ def binary_scan_all(cnf, limit): - Logger = daklog.Logger(cnf.Cnf, 'contents scan-binary') + Logger = daklog.Logger('contents scan-binary') result = BinaryContentsScanner.scan_all(limit) processed = '%(processed)d packages processed' % result remaining = '%(remaining)d packages remaining' % result @@ -102,7 +102,7 @@ def binary_scan_all(cnf, limit): ################################################################################ def source_scan_all(cnf, limit): - Logger = daklog.Logger(cnf.Cnf, 'contents scan-source') + Logger = daklog.Logger('contents scan-source') result = SourceContentsScanner.scan_all(limit) processed = '%(processed)d packages processed' % result remaining = '%(remaining)d packages remaining' % result diff --git a/dak/control_overrides.py b/dak/control_overrides.py index befc35d2..803c8951 100755 --- a/dak/control_overrides.py +++ b/dak/control_overrides.py @@ -353,7 +353,7 @@ def main (): utils.warn("In No-Action Mode") action = False - Logger = daklog.Logger(cnf.Cnf, "control-overrides", mode) + Logger = daklog.Logger("control-overrides", mode) if file_list: for f in file_list: process_file(utils.open_file(f), suite, component, otype, mode, action, session) diff --git a/dak/control_suite.py b/dak/control_suite.py index 740b8836..ed4f6b1a 100755 --- a/dak/control_suite.py +++ b/dak/control_suite.py @@ -424,7 +424,7 @@ def main (): if action == "list": get_list(suite, session) else: - Logger = daklog.Logger(cnf.Cnf, "control-suite") + Logger = daklog.Logger("control-suite") if file_list: for f in file_list: process_file(utils.open_file(f), suite, action, session, britney, force) diff --git a/dak/dak.py b/dak/dak.py index b8b9f62d..2a3c2308 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -178,7 +178,7 @@ def main(): try: - logger = Logger(Config(), 'dak top-level', print_starting=False) + logger = Logger('dak top-level', print_starting=False) except CantOpenError: logger = None diff --git a/dak/dominate.py b/dak/dominate.py index 7bb74c67..483ab28a 100755 --- a/dak/dominate.py +++ b/dak/dominate.py @@ -136,7 +136,7 @@ def main(): Options = cnf.SubTree("Obsolete::Options") if Options['Help']: usage() - Logger = daklog.Logger(cnf.Cnf, "dominate") + Logger = daklog.Logger("dominate") session = DBConn().session() for suite_name in utils.split_args(Options['Suite']): suite = session.query(Suite).filter_by(suite_name = suite_name).one() diff --git a/dak/external_overrides.py b/dak/external_overrides.py index 9e212061..6072c5a6 100755 --- a/dak/external_overrides.py +++ b/dak/external_overrides.py @@ -125,7 +125,7 @@ def main(): if Options.has_key("Force") and Options["Force"]: force = True - logger = daklog.Logger(cnf, 'external-overrides') + logger = daklog.Logger('external-overrides') command = args[0] if command in ('import', 'i'): diff --git a/dak/generate_filelist.py b/dak/generate_filelist.py index 98d239c5..7823295f 100755 --- a/dak/generate_filelist.py +++ b/dak/generate_filelist.py @@ -132,7 +132,7 @@ Incremental mode appends only newer files to existing lists.""" def main(): cnf = Config() - Logger = daklog.Logger(cnf, 'generate-filelist') + Logger = daklog.Logger('generate-filelist') Arguments = [('h', "help", "Filelist::Options::Help"), ('s', "suite", "Filelist::Options::Suite", "HasArg"), ('c', "component", "Filelist::Options::Component", "HasArg"), diff --git a/dak/generate_packages_sources.py b/dak/generate_packages_sources.py index 5ef036da..e78466fc 100755 --- a/dak/generate_packages_sources.py +++ b/dak/generate_packages_sources.py @@ -468,7 +468,7 @@ def main (): if Options["Help"]: usage() - Logger = daklog.Logger(cnf, 'generate-packages-sources') + Logger = daklog.Logger('generate-packages-sources') session = DBConn().session() diff --git a/dak/generate_packages_sources2.py b/dak/generate_packages_sources2.py index f3c843b5..d29e0317 100755 --- a/dak/generate_packages_sources2.py +++ b/dak/generate_packages_sources2.py @@ -255,7 +255,7 @@ def main(): if Options.has_key("Help"): usage() - logger = daklog.Logger(cnf, 'generate-packages-sources2') + logger = daklog.Logger('generate-packages-sources2') session = DBConn().session() diff --git a/dak/generate_releases.py b/dak/generate_releases.py index 30063646..0a394274 100755 --- a/dak/generate_releases.py +++ b/dak/generate_releases.py @@ -306,7 +306,7 @@ def main (): if Options["Help"]: usage() - Logger = daklog.Logger(cnf, 'generate-releases') + Logger = daklog.Logger('generate-releases') session = DBConn().session() diff --git a/dak/make_maintainers.py b/dak/make_maintainers.py index 0733f3bc..8e93f8af 100755 --- a/dak/make_maintainers.py +++ b/dak/make_maintainers.py @@ -77,7 +77,7 @@ def main(): if Options["Help"]: usage() - Logger = daklog.Logger(cnf.Cnf, 'make-maintainers') + Logger = daklog.Logger('make-maintainers') session = DBConn().session() # dictionary packages to maintainer names diff --git a/dak/manage_build_queues.py b/dak/manage_build_queues.py index e9486adf..a292b4ae 100755 --- a/dak/manage_build_queues.py +++ b/dak/manage_build_queues.py @@ -73,7 +73,7 @@ def main (): if Options["Help"]: usage() - Logger = daklog.Logger(cnf, 'manage-build-queues', Options['No-Action']) + Logger = daklog.Logger('manage-build-queues', Options['No-Action']) starttime = datetime.now() diff --git a/dak/metadata.py b/dak/metadata.py index f40c9431..1fe32110 100755 --- a/dak/metadata.py +++ b/dak/metadata.py @@ -66,7 +66,7 @@ OPTIONS for scan ################################################################################ def scan_all(cnf, mode, limit): - Logger = daklog.Logger(cnf.Cnf, 'metadata scan (%s)' % mode) + Logger = daklog.Logger('metadata scan (%s)' % mode) result = MetadataScanner.scan_all(mode, limit) processed = '%(processed)d %(type)s processed' % result remaining = '%(remaining)d %(type)s remaining' % result diff --git a/dak/new_security_install.py b/dak/new_security_install.py index 2048e215..2dd2820f 100755 --- a/dak/new_security_install.py +++ b/dak/new_security_install.py @@ -155,7 +155,7 @@ def main(): Options["Sudo"] = "" if not Options["Sudo"] and not Options["No-Action"]: - Logger = daklog.Logger(cnf.Cnf, "security-install") + Logger = daklog.Logger("security-install") session = DBConn().session() diff --git a/dak/override.py b/dak/override.py index 13a277db..3d2a9aba 100755 --- a/dak/override.py +++ b/dak/override.py @@ -254,7 +254,7 @@ def main (): game_over() - Logger = daklog.Logger(cnf.Cnf, "override") + Logger = daklog.Logger("override") dsc_otype_id = get_override_type('dsc').overridetype_id diff --git a/dak/process_new.py b/dak/process_new.py index 11e9bf48..5899a9cc 100755 --- a/dak/process_new.py +++ b/dak/process_new.py @@ -784,7 +784,7 @@ def main(): if not Options["No-Action"]: try: - Logger = daklog.Logger(cnf, "process-new") + Logger = daklog.Logger("process-new") except CantOpenError, e: Options["Trainee"] = "True" diff --git a/dak/process_policy.py b/dak/process_policy.py index dfe538fb..94e27468 100755 --- a/dak/process_policy.py +++ b/dak/process_policy.py @@ -141,7 +141,7 @@ def main(): if not Options["No-Action"]: try: - Logger = daklog.Logger(cnf, "process-policy") + Logger = daklog.Logger("process-policy") except CantOpenError, e: Logger = None diff --git a/dak/process_upload.py b/dak/process_upload.py index 12e25a33..f74993ce 100755 --- a/dak/process_upload.py +++ b/dak/process_upload.py @@ -469,7 +469,7 @@ def main(): log_urgency = True UrgencyLog() - Logger = daklog.Logger(cnf, "process-upload", Options["No-Action"]) + Logger = daklog.Logger("process-upload", Options["No-Action"]) # If we have a directory flag, use it to find our files if cnf["Dinstall::Options::Directory"] != "": diff --git a/dak/update_db.py b/dak/update_db.py index 02ded358..91c8211f 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -119,7 +119,7 @@ Updates dak's database schema to the lastest version. You should disable crontab # Ok, try and find the configuration table print "Determining dak database revision ..." cnf = Config() - logger = Logger(cnf.Cnf, 'update-db') + logger = Logger('update-db') try: # Build a connect string diff --git a/daklib/daklog.py b/daklib/daklog.py index 856dc841..7ececa56 100644 --- a/daklib/daklog.py +++ b/daklib/daklog.py @@ -36,28 +36,20 @@ class Logger(object): "Logger object" __shared_state = {} - def __init__(self, *args, **kwargs): + def __init__(self, program='unknown', debug=False, print_starting=True, include_pid=False): self.__dict__ = self.__shared_state - if not getattr(self, 'initialised', False): - from daklib.config import Config - self.initialised = True - - # To be backwards compatibile, dump the first argument if it's a - # Config object. TODO: Fix up all callers and remove this - if len(args) > 0 and isinstance(args[0], Config): - args = list(args) - args.pop(0) - - self.__setup(*args, **kwargs) - - - def __setup(self, program='unknown', debug=False, print_starting=True, include_pid=False): - "Initialize a new Logger object" self.program = program self.debug = debug self.include_pid = include_pid + if not getattr(self, 'logfile', None): + self._open_log(debug) + + if print_starting: + self.log(["program start"]) + + def _open_log(self, debug): # Create the log directory if it doesn't exist from daklib.config import Config logdir = Config()["Dir::Log"] @@ -79,9 +71,6 @@ class Logger(object): self.logfile = logfile - if print_starting: - self.log(["program start"]) - def log (self, details): "Log an event" # Prepend timestamp, program name, and user name