summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Singleton <matt@xcolour.net>2017-04-20 13:38:04 -0400
committerMatt Singleton <matt@xcolour.net>2017-04-20 13:38:04 -0400
commitdeca37e1ae9da82bfd4ef5edf95fd9c22b871cd0 (patch)
treefbbdb1a702b87917d026863d5d99346894992171
parent9a8eff98fc5dec755683ce1708bf0caf578c5752 (diff)
switch to dict logging and configure separate log writers for console and debug
-rwxr-xr-xunbiased/main.py41
1 files changed, 35 insertions, 6 deletions
diff --git a/unbiased/main.py b/unbiased/main.py
index ba72710..df2b209 100755
--- a/unbiased/main.py
+++ b/unbiased/main.py
@@ -2,19 +2,48 @@
import argparse
import logging
+import logging.config
import time
from unbiased.unbiasedObjects import *
from unbiased.unbiasedFunctions import *
from unbiased.parser import *
+logging.config.dictConfig({
+ 'version': 1,
+ 'formatters': {
+ 'console': {
+ 'format': '%(levelname)s %(filename)s:%(lineno)d %(message)s',
+ },
+ 'file': {
+ 'format': '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s',
+ },
+ },
+ 'handlers': {
+ 'console': {
+ 'class': 'logging.StreamHandler',
+ 'level': 'INFO',
+ 'formatter': 'console',
+ },
+ 'file': {
+ 'class': 'logging.handlers.RotatingFileHandler',
+ 'level': 'DEBUG',
+ 'formatter': 'file',
+ 'filename': '/opt/unbiased/logs/unbiased.debug.log',
+ 'maxBytes': 1024 * 1024,
+ 'backupCount': 3,
+ },
+ },
+ 'loggers': {
+ 'unbiased': {
+ 'handlers': ['console', 'file'],
+ },
+ },
+ 'root': {
+ 'level': 'DEBUG',
+ }
+})
logger = logging.getLogger('unbiased')
-logger.setLevel(logging.DEBUG)
-ch = logging.StreamHandler()
-ch.setLevel(logging.DEBUG)
-ch.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
-logger.addHandler(ch)
-
def main():
parser = argparse.ArgumentParser()