From fd43701eb565f73389029a4f5ee20a1163729aa4 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Mon, 28 Nov 2016 00:00:23 +0100 Subject: Dedup log initialisation code. --- tools/merge_backup.py | 7 +------ tools/merge_dist.py | 9 ++------- tools/merge_fetch.py | 9 ++------- tools/merge_sth.py | 9 ++------- tools/mergetools.py | 9 +++++++++ 5 files changed, 16 insertions(+), 27 deletions(-) (limited to 'tools') diff --git a/tools/merge_backup.py b/tools/merge_backup.py index c057b5a..b0c7289 100755 --- a/tools/merge_backup.py +++ b/tools/merge_backup.py @@ -229,12 +229,7 @@ def main(): lockfile = mergedb + "/.merge_backup.lock" fetched_path = mergedb + "/fetched" - loglevel = getattr(logging, args.loglevel.upper()) - if args.mergeinterval is None: - logging.basicConfig(level=loglevel) - else: - logging.basicConfig(filename=args.logdir + "/merge_backup.log", - level=loglevel) + loginit(args, "merge_backup.log") if not flock_ex_or_fail(lockfile): logging.critical("unable to take lock %s", lockfile) diff --git a/tools/merge_dist.py b/tools/merge_dist.py index ffddc25..d612600 100755 --- a/tools/merge_dist.py +++ b/tools/merge_dist.py @@ -18,7 +18,7 @@ from certtools import timing_point, create_ssl_context from mergetools import get_curpos, get_logorder, chunks, get_missingentries, \ publish_sth, sendlog, sendentries, parse_args, perm, \ get_frontend_verifiedsize, frontend_verify_entries, \ - waitforfile, flock_ex_or_fail, Status + waitforfile, flock_ex_or_fail, Status, loginit def sendlog_helper(entries, curpos, nodename, nodeaddress, own_key, paths, statusupdates): @@ -155,12 +155,7 @@ def main(): lockfile = mergedb + "/.merge_dist.lock" timestamp = 0 - loglevel = getattr(logging, args.loglevel.upper()) - if args.mergeinterval is None: - logging.basicConfig(level=loglevel) - else: - logging.basicConfig(filename=args.logdir + "/merge_dist.log", - level=loglevel) + loginit(args, "merge_dist.log") if not flock_ex_or_fail(lockfile): logging.critical("unable to take lock %s", lockfile) diff --git a/tools/merge_fetch.py b/tools/merge_fetch.py index d5a514b..801f9cf 100755 --- a/tools/merge_fetch.py +++ b/tools/merge_fetch.py @@ -20,7 +20,7 @@ from itertools import cycle from mergetools import get_logorder, verify_entry, get_new_entries, \ chunks, fsync_logorder, get_entries, add_to_logorder, \ hexencode, hexdecode, parse_args, perm, flock_ex_or_fail, Status, \ - terminate_child_procs + terminate_child_procs, loginit from certtools import timing_point, write_file, create_ssl_context def merge_fetch_sequenced(args, config, localconfig): @@ -297,12 +297,7 @@ def main(): currentsizefile = mergedb + "/fetched" lockfile = mergedb + "/.merge_fetch.lock" - loglevel = getattr(logging, args.loglevel.upper()) - if args.mergeinterval is None: - logging.basicConfig(level=loglevel) - else: - logging.basicConfig(filename=args.logdir + "/merge_fetch.log", - level=loglevel) + loginit(args, "merge_fetch.log") if not flock_ex_or_fail(lockfile): logging.critical("unable to take lock %s", lockfile) diff --git a/tools/merge_sth.py b/tools/merge_sth.py index 97f6e24..9dd7a70 100755 --- a/tools/merge_sth.py +++ b/tools/merge_sth.py @@ -15,7 +15,7 @@ import logging from base64 import b64encode from datetime import datetime, timedelta from mergetools import parse_args, get_nfetched, hexencode, hexdecode, \ - get_logorder, get_sth, flock_ex_or_fail + get_logorder, get_sth, flock_ex_or_fail, loginit from certtools import create_ssl_context, get_public_key_from_file, \ timing_point, create_sth_signature, write_file, check_sth_signature, \ build_merkle_tree @@ -130,12 +130,7 @@ def main(): mergedb = paths["mergedb"] lockfile = mergedb + "/.merge_sth.lock" - loglevel = getattr(logging, args.loglevel.upper()) - if args.mergeinterval is None: - logging.basicConfig(level=loglevel) - else: - logging.basicConfig(filename=args.logdir + "/merge_sth.log", - level=loglevel) + loginit(args, "merge_sth.log") if not flock_ex_or_fail(lockfile): logging.critical("unable to take lock %s", lockfile) diff --git a/tools/mergetools.py b/tools/mergetools.py index 1334186..109e9d4 100644 --- a/tools/mergetools.py +++ b/tools/mergetools.py @@ -489,6 +489,15 @@ def terminate_child_procs(): #print >>sys.stderr, "DEBUG: terminating pid", p.pid p.terminate() +def loginit(args, fname): + logfmt = '%(asctime)s %(message)s' + loglevel = getattr(logging, args.loglevel.upper()) + if args.logdir is None: + logging.basicConfig(format=logfmt, level=loglevel) + else: + logging.basicConfig(format=logfmt, level=loglevel, + filename=args.logdir + "/" + fname) + class Status: def __init__(self, path): self.path = path -- cgit v1.1