commit 54824e5e27b48b43324d92d2f67b8dc1d4b44a4a Author: Christian Fromme kaner@strace.org Date: Sun Feb 20 16:57:21 2011 +0100
Clean up logging --- gettor.conf | 4 ++-- lib/GetTor.py | 19 +++++++++++++++++-- lib/gettor/gtlog.py | 25 ------------------------- 3 files changed, 19 insertions(+), 29 deletions(-)
diff --git a/gettor.conf b/gettor.conf index a62aac6..12b85d3 100644 --- a/gettor.conf +++ b/gettor.conf @@ -15,7 +15,7 @@ DEFAULT_LOCALE = "en" DELAY_ALERT = True
# Basename of the GetTor log files. Will be expandet to $LOGFILE-YYYY-MM-DD.log -LOGFILE = "gettorlog" +LOGFILE = "gettor_log"
# What log level should we use? LOGLEVEL = "DEBUG" @@ -24,7 +24,7 @@ LOGLEVEL = "DEBUG" PASSFILE = "gettor.pass"
# Where do we dump erronous emails? -DUMPFILE = "./gettor.dump" +DUMPFILE = "gettor.dump"
# Do we send every mail type to every user only once before we blacklist them # for it? diff --git a/lib/GetTor.py b/lib/GetTor.py index ca058be..68f9ddf 100644 --- a/lib/GetTor.py +++ b/lib/GetTor.py @@ -15,12 +15,27 @@ except ImportError: import os import sys import logging -import gettor.gtlog import gettor.opt import gettor.config import gettor.requests import gettor.responses import gettor.utils +from time import strftime + + +def initializeLogging(cfg): + level = getattr(cfg, 'LOGLEVEL', 'WARNING') + level = getattr(logging, level) + extra = {} + logfileName = cfg.LOGFILE + "-" + strftime("%Y-%m-%d") + ".log" + extra['filename'] = os.path.join(cfg.BASEDIR, logfileName) + + print "Logfile is %s" % extra['filename'] + + logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', + datefmt="%b %d %H:%M:%S", + level=level, + **extra)
def processFail(conf, rawMessage, reqval, failedAction, e=None): """This routine gets called when something went wrong with the processing @@ -102,7 +117,7 @@ def main(): """ options, arguments = gettor.opt.parseOpts() config = gettor.config.Config(options.configfile) - gettor.gtlog.initialize(config) + initializeLogging(config)
if sys.stdin.isatty(): # We separate this because we need a way to know how we reply to the diff --git a/lib/gettor/gtlog.py b/lib/gettor/gtlog.py deleted file mode 100644 index 53b20f3..0000000 --- a/lib/gettor/gtlog.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2008 - 2011, Jacob Appelbaum jacob@appelbaum.net, -# Christian Fromme kaner@strace.org -# This is Free Software. See LICENSE for license information. - -from time import strftime -import logging - -__all__ = ["initalize"] - -def initialize(cfg): - level = getattr(cfg, 'LOGLEVEL', 'WARNING') - level = getattr(logging, level) - extra = {} - if getattr(cfg, "LOGFILE"): - extra['filename'] = cfg.LOGFILE - else: - extra['filename'] = "./gettor_log" - - extra['filename'] += "-" + strftime("%Y-%m-%d") + ".log" - print "Logfile is %s" % extra['filename'] - - logging.basicConfig(format='%(asctime)s [%(levelname)s] %(message)s', - datefmt="%b %d %H:%M:%S", - level=level, - **extra)