Skip to content

Commit

Permalink
support timezone in cup logging
Browse files Browse the repository at this point in the history
cup logging
  • Loading branch information
mythmgn committed Nov 8, 2020
1 parent a761766 commit 3bf502f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cup/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os
import re
import sys
import time
import uuid
import logging
from logging import handlers
Expand Down Expand Up @@ -135,9 +136,12 @@ def setup_filelogger(cls, logger, logparams):
)
logger.setLevel(loglevel)
# '%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s - %(message)s'
tznum = time.strftime('%z')
tzkey = time.strftime('%Z')
formatter = logging.Formatter(
'%(levelname)s:\t %(asctime)s * '
fmt='%(levelname)s:\t %(asctime)s {0}({1}) * '
'[%(process)d:%(thread)x] [%(filename)s:%(lineno)s] %(message)s'
.format(tznum, tzkey)
)
if bprint_console:
info('bprint_console enabled, will print to stdout')
Expand Down Expand Up @@ -471,7 +475,9 @@ def parse(logline):
'pid': 8808,
'tid': 1111111,
'srcline': 'util.py:33',
'msg': 'this is the log content'
'msg': 'this is the log content',
'tznum': 8,
'tzstr': 'CST'
}
"""
Expand All @@ -481,16 +487,19 @@ def parse(logline):
content = content[(content.find(']') + 1):].strip()
regex = re.compile('[ \t]+')
items = regex.split(logline)
loglevel, date, time_, _, pid_tid, src = items[0:6]
loglevel, date, time_, timezone, _, pid_tid, src = items[0:6]
pid, tid = pid_tid.strip('[]').split(':')
tznum, tzkey = timezone.strip('+)').split('(')
return {
'loglevel': loglevel.strip(':'),
'date': date,
'time': time_,
'pid': pid,
'tid': tid,
'srcline': src.strip('[]'),
'msg': content
'msg': content,
'tznum': int(tznum),
'tzkey': tzkey
}
# pylint: disable = W0703
except Exception:
Expand Down

0 comments on commit 3bf502f

Please sign in to comment.