Add timestamps to log lines.
This commit is contained in:
parent
0881f43d85
commit
013e79cd6b
2 changed files with 14 additions and 4 deletions
|
@ -249,7 +249,14 @@ def main_log_context(subject, level, **kwargs):
|
|||
log = vlogging.getLogger()
|
||||
handler = LogHandler(subject, **kwargs)
|
||||
handler.setLevel(level)
|
||||
handler.setFormatter(vlogging.Formatter('{levelname}:{name}:{message}', style='{'))
|
||||
datefmt = '%Y-%m-%dT%H:%M:%S'
|
||||
formatter = vlogging.Formatter(
|
||||
'[{asctime}.{msecs:03.0f}] {levelname}:{name}:{message}',
|
||||
style='{',
|
||||
datefmt=datefmt,
|
||||
)
|
||||
formatter.default_msec_format = '%s.%03d'
|
||||
handler.setFormatter(formatter)
|
||||
context = LogHandlerContext(log, handler)
|
||||
return context
|
||||
|
||||
|
|
|
@ -54,12 +54,15 @@ def add_loud(log):
|
|||
|
||||
def add_root_handler(level):
|
||||
handler = StreamHandler()
|
||||
datefmt = '%Y-%m-%dT%H:%M:%S'
|
||||
if level <= LOUD:
|
||||
handler.setFormatter(Formatter('{levelname}:{name}.{funcName}.{lineno}:{message}', style='{'))
|
||||
formatter = Formatter('[{asctime}.{msecs:03.0f}] {levelname}:{name}.{funcName}.{lineno}:{message}', style='{', datefmt=datefmt)
|
||||
elif level <= DEBUG:
|
||||
handler.setFormatter(Formatter('{levelname}:{name}.{funcName}:{message}', style='{'))
|
||||
formatter = Formatter('[{asctime}.{msecs:03.0f}] {levelname}:{name}.{funcName}:{message}', style='{', datefmt=datefmt)
|
||||
else:
|
||||
handler.setFormatter(Formatter('{levelname}:{name}:{message}', style='{'))
|
||||
formatter = Formatter('[{asctime}.{msecs:03.0f}] {levelname}:{name}:{message}', style='{', datefmt=datefmt)
|
||||
formatter.default_msec_format = '%s.%03d'
|
||||
handler.setFormatter(formatter)
|
||||
handler.setLevel(level)
|
||||
root.addHandler(handler)
|
||||
return handler
|
||||
|
|
Loading…
Reference in a new issue