From 1feb88ed437906d23ae124398eb00940578937e9 Mon Sep 17 00:00:00 2001 From: jamessynge Date: Fri, 5 Oct 2018 16:48:34 -0400 Subject: [PATCH 1/3] Remove support for the 'fileline' attribute in log formats This non-standard attribute has been the cause of many problems, so reverting back to using only the default attributes. --- conf_files/log.yaml | 3 +-- pocs/utils/logger.py | 12 ------------ scripts/run_social_messaging.py | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/conf_files/log.yaml b/conf_files/log.yaml index b33428f91..b5b328690 100644 --- a/conf_files/log.yaml +++ b/conf_files/log.yaml @@ -7,8 +7,7 @@ logger: datefmt: '%H:%M:%S' detail: style: '{' - # See FilenameLineFilter in logger.py for fileline description - format: '{levelname:.1s}{asctime}.{msecs:03.0f} {fileline:20s} {message}' + format: '{levelname:.1s}{asctime}.{msecs:03.0f} {filename} {lineno} {message}' datefmt: '%m%d %H:%M:%S' handlers: all: diff --git a/pocs/utils/logger.py b/pocs/utils/logger.py index 4af720dd3..68f94389c 100644 --- a/pocs/utils/logger.py +++ b/pocs/utils/logger.py @@ -127,9 +127,6 @@ def get_root_logger(profile='panoptes', log_config=None): # Set custom LogRecord logging.setLogRecordFactory(StrFormatLogRecord) - # Add a filter for better filename/lineno - logger.addFilter(FilenameLineFilter()) - logger.info('{:*^80}'.format(' Starting PanLogger ')) # TODO(jamessynge) Output name of script, cmdline args, etc. And do son # when the log rotates too! @@ -141,12 +138,3 @@ class _UTCFormatter(logging.Formatter): """ Simple class to convert times to UTC in the logger """ converter = time.gmtime - - -class FilenameLineFilter(logging.Filter): - """Adds a simple concatenation of filename and lineno for fixed length """ - - def filter(self, record): - - record.fileline = '{}:{}'.format(record.filename, record.lineno) - return True diff --git a/scripts/run_social_messaging.py b/scripts/run_social_messaging.py index dfb006564..fc4cb24c2 100755 --- a/scripts/run_social_messaging.py +++ b/scripts/run_social_messaging.py @@ -97,7 +97,7 @@ def run_social_sinks(msg_port, social_twitter, social_slack): # This is early in startup to ensure the PANOPTES logging code is # installed early. Unfortunately this doesn't (yet) prevent the # problem with our format keyword 'fileline' causing problems for - # other loggers. + # other loggers. See issue #393. pocs_config = load_config() the_root_logger = get_root_logger() From 995eb22dc3aa87c00d1969f42476981925d7432d Mon Sep 17 00:00:00 2001 From: jamessynge Date: Fri, 5 Oct 2018 17:41:46 -0400 Subject: [PATCH 2/3] Format filename and lineno for easier readability Right align the filename in a 25 char field space (if it fits), and pad the lineno to 3 chars with zero if lower than 100. For most of our files, this will result in a fixed length prefix before the message, thus making it somewhat easier to find the message. --- conf_files/log.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf_files/log.yaml b/conf_files/log.yaml index b5b328690..cbf43251a 100644 --- a/conf_files/log.yaml +++ b/conf_files/log.yaml @@ -7,7 +7,7 @@ logger: datefmt: '%H:%M:%S' detail: style: '{' - format: '{levelname:.1s}{asctime}.{msecs:03.0f} {filename} {lineno} {message}' + format: '{levelname:.1s}{asctime}.{msecs:03.0f} {filename:>25s}:{lineno:03d} {message}' datefmt: '%m%d %H:%M:%S' handlers: all: From 6482e77008379c10ef8aeda06b6b32c4b1001e51 Mon Sep 17 00:00:00 2001 From: jamessynge Date: Fri, 5 Oct 2018 17:46:22 -0400 Subject: [PATCH 3/3] Add ] as a marker/separator to log lines. The ] will be on all log lines, between the (usually) fixed length prefix and the message. --- conf_files/log.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf_files/log.yaml b/conf_files/log.yaml index cbf43251a..564e40742 100644 --- a/conf_files/log.yaml +++ b/conf_files/log.yaml @@ -7,7 +7,7 @@ logger: datefmt: '%H:%M:%S' detail: style: '{' - format: '{levelname:.1s}{asctime}.{msecs:03.0f} {filename:>25s}:{lineno:03d} {message}' + format: '{levelname:.1s}{asctime}.{msecs:03.0f} {filename:>25s}:{lineno:03d}] {message}' datefmt: '%m%d %H:%M:%S' handlers: all: