From deca37e1ae9da82bfd4ef5edf95fd9c22b871cd0 Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Thu, 20 Apr 2017 13:38:04 -0400 Subject: switch to dict logging and configure separate log writers for console and debug --- unbiased/main.py | 41 +++++++++++++++++++++++++++++++++++------ 1 file 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() -- cgit v1.2.3