Skip to content

Commit

Permalink
Remove support for the 'fileline' attribute in log formats (#678)
Browse files Browse the repository at this point in the history
This non-standard attribute has been the cause of many problems,
so reverting back to using only the default attributes, in particular
filename and lineno.

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.

Adding ] as a marker/separator to log lines. The ] will be on all log lines,
between the (usually) fixed length prefix and the message.
  • Loading branch information
jamessynge authored Oct 6, 2018
1 parent c608618 commit df915fd
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 15 deletions.
3 changes: 1 addition & 2 deletions conf_files/log.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:>25s}:{lineno:03d}] {message}'
datefmt: '%m%d %H:%M:%S'
handlers:
all:
Expand Down
12 changes: 0 additions & 12 deletions pocs/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
2 changes: 1 addition & 1 deletion scripts/run_social_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit df915fd

Please sign in to comment.