0

Use a terse logging line if --verbose is not specified

This commit is contained in:
Andrew Chin
2011-11-03 20:41:02 -04:00
parent 2dc1496432
commit 42593bab58
2 changed files with 42 additions and 19 deletions

View File

@@ -224,13 +224,17 @@ class HighlightingFormatter(logging.Formatter):
"""Base class of our custom formatter
"""
fmtstr = '%(fileandlineno)-18s:PID(%(pid)s):%(asctime)s ' \
'%(levelname)-8s %(message)s'
datefmt = "%H:%M:%S"
datefmt = "%Y-%m-%d %H:%M:%S"
funcName_len = 15
def __init__(self):
logging.Formatter.__init__(self, self.fmtstr, self.datefmt)
def __init__(self, verbose=False):
if verbose:
fmtstr = '%(fileandlineno)-18s %(pid)s %(asctime)s ' \
'%(levelname)-8s %(message)s'
else:
fmtstr = '%(asctime)s ' '%(shortlevelname)-1s%(message)s'
logging.Formatter.__init__(self, fmtstr, self.datefmt)
def format(self, record):
"""Add a few extra options to the record
@@ -244,8 +248,15 @@ class HighlightingFormatter(logging.Formatter):
funcName
The function name truncated/padded to a fixed width characters
shortlevelname
The level name truncated to 1 character
"""
record.shortlevelname = record.levelname[0] + ' '
if record.levelname == 'INFO': record.shortlevelname = ''
record.pid = os.getpid()
record.fileandlineno = "%s:%s" % (record.filename, record.lineno)