Log formatting
This commit is contained in:
parent
b58b9fc188
commit
f1805138f6
19
app/log.py
19
app/log.py
@ -6,6 +6,18 @@ import logging.handlers
|
||||
from config import Config
|
||||
|
||||
|
||||
class LevelTagFilter(logging.Filter):
|
||||
"Add leveltag"
|
||||
|
||||
def filter(self, record):
|
||||
# Extract the first character of the level name
|
||||
record.leveltag = record.levelname[0]
|
||||
|
||||
# We never actually filter messages out, just abuse filtering to add an
|
||||
# extra field to the LogRecord
|
||||
return True
|
||||
|
||||
|
||||
log = logging.getLogger("musicmuster")
|
||||
log.setLevel(logging.DEBUG)
|
||||
|
||||
@ -17,8 +29,13 @@ stderr.setLevel(Config.LOG_LEVEL_STDERR)
|
||||
syslog = logging.handlers.SysLogHandler(address='/dev/log')
|
||||
syslog.setLevel(Config.LOG_LEVEL_SYSLOG)
|
||||
|
||||
# Filter
|
||||
filter = LevelTagFilter()
|
||||
syslog.addFilter(filter)
|
||||
stderr.addFilter(filter)
|
||||
|
||||
# create formatter and add it to the handlers
|
||||
formatter = logging.Formatter('[%(name)s:%(levelname)s]: %(message)s')
|
||||
formatter = logging.Formatter('[%(name)s] %(leveltag)s: %(message)s')
|
||||
stderr.setFormatter(formatter)
|
||||
syslog.setFormatter(formatter)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user