From d86ba5f99e61ff81ab750aba226df8b8a78dcae5 Mon Sep 17 00:00:00 2001 From: kaliko Date: Wed, 11 Feb 2015 23:51:11 +0100 Subject: [PATCH] Add trace level to the logger --- sima/lib/logger.py | 16 +++++++++++++++- sima/lib/webserv.py | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sima/lib/logger.py b/sima/lib/logger.py index 09d7a69..2079406 100644 --- a/sima/lib/logger.py +++ b/sima/lib/logger.py @@ -26,6 +26,8 @@ Logging facility for sima. import logging import sys +from os import environ + DEBUG = logging.DEBUG INFO = logging.INFO ERROR = logging.ERROR @@ -37,6 +39,15 @@ 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): """ @@ -46,7 +57,10 @@ def set_logger(level='info', logfile=None): """ name = 'sima' - user_log_level = getattr(logging, level.upper()) + if environ.get('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: diff --git a/sima/lib/webserv.py b/sima/lib/webserv.py index 0a04ddb..6a127f4 100644 --- a/sima/lib/webserv.py +++ b/sima/lib/webserv.py @@ -269,6 +269,8 @@ class WebService(Plugin): self.log.warning('Got nothing from music library.') return [] queued_artists = MetaContainer([trk.Artist for trk in self.player.queue]) + self.log.trace('Already queued: {}'.format(queued_artists)) + self.log.trace('Candidate: {}'.format(ret)) if ret & queued_artists: self.log.debug('Removing already queued artists: ' '{0}'.format('/'.join(map(str, ret & queued_artists)))) -- 2.39.2