diff options
author | 2009-07-29 15:42:39 +0200 | |
---|---|---|
committer | 2009-07-29 15:42:39 +0200 | |
commit | f3ac176bc3db9018393bebf5ad5dbf9a056fa56d (patch) | |
tree | dbdefd5f71fa10e9f97c9cae92ffd4b67ab31c0f | |
parent | Added top-level exception handling (diff) | |
download | collagen-f3ac176bc3db9018393bebf5ad5dbf9a056fa56d.tar.gz collagen-f3ac176bc3db9018393bebf5ad5dbf9a056fa56d.tar.bz2 collagen-f3ac176bc3db9018393bebf5ad5dbf9a056fa56d.zip |
Reset FileHandler when calling init_logging
I saw no direct way to reset when using basicConfig unfortunately...
-rw-r--r-- | src/tinderbox/logger.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/tinderbox/logger.py b/src/tinderbox/logger.py index d73b7f3..a90f578 100644 --- a/src/tinderbox/logger.py +++ b/src/tinderbox/logger.py @@ -3,14 +3,23 @@ from errno import * import logging as log import config +fhandler = None + def init_logging(dir): """Initialize logging file and settings """ + global fhandler try: os.mkdir(dir) except OSError, e: if e.errno != EEXIST: raise e - log.basicConfig(level=config.LOG_LEVEL, format='%(asctime)s %(levelname)s %(message)s', - filename=dir+'/tinderbox.log', filemode='a') + if fhandler is not None: + fhandler.close() + log.getLogger('').removeHandler(fhandler) + fhandler = log.FileHandler(dir+"/tinderbox.log") + formatter = log.Formatter('%(asctime)s %(levelname)s %(message)s') + fhandler.setFormatter(formatter) + log.getLogger('').addHandler(fhandler) + fhandler.setLevel(config.LOG_LEVEL) |