X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Flib%2Flogger.py;h=b9b8b408ecfdc60ed34406870ab117882faf733c;hb=b374f36f34ce368fbfc2b8b56b784aa45b27ec7e;hp=09d7a69ce2c413cad9896366e5b9d2c953ef76cb;hpb=0c911454ac7f8377003a5f0d90244aa3f06b2695;p=mpd-sima.git diff --git a/sima/lib/logger.py b/sima/lib/logger.py index 09d7a69..b9b8b40 100644 --- a/sima/lib/logger.py +++ b/sima/lib/logger.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (c) 2009, 2010, 2013, 2014, 2015 Jack Kaliko +# Copyright (c) 2009, 2010, 2013, 2014, 2015 kaliko # # This file is part of sima # @@ -26,6 +26,8 @@ Logging facility for sima. import logging import sys +from os import getenv + DEBUG = logging.DEBUG INFO = logging.INFO ERROR = logging.ERROR @@ -37,16 +39,27 @@ LOG_FORMATS = { } DATE_FMT = "%Y-%m-%d %H:%M:%S" +TRACE_LEVEL_NUM = 5 +logging.addLevelName(TRACE_LEVEL_NUM, 'TRACE') +def trace(self, message, *args, **kwargs): + # Yes, logger takes its '*args' as 'args'. + if self.isEnabledFor(TRACE_LEVEL_NUM): + self._log(TRACE_LEVEL_NUM, message, args, **kwargs) + +logging.Logger.trace = trace + def set_logger(level='info', logfile=None): """ logger: level: in debug, info, warning,… logfile: file to log to - """ name = 'sima' - user_log_level = getattr(logging, level.upper()) + if getenv('TRACE', False): + user_log_level = TRACE_LEVEL_NUM + else: + user_log_level = getattr(logging, level.upper()) if user_log_level > DEBUG: log_format = LOG_FORMATS.get(INFO) else: