include package namespace and line number in logger output
This commit is contained in:
parent
615e224162
commit
f387b7bf04
1 changed files with 13 additions and 7 deletions
|
@ -9,6 +9,7 @@
|
||||||
:license: BSD, see LICENSE for more details.
|
:license: BSD, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -47,14 +48,19 @@ class JsonFormatter(logging.Formatter):
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
data = OrderedDict([
|
data = OrderedDict([
|
||||||
('now', self.formatTime(record, self.datefmt)),
|
('now', self.formatTime(record, self.datefmt)),
|
||||||
('version', self.version),
|
|
||||||
('plugin', self.plugin),
|
|
||||||
('time', self.timestamp),
|
|
||||||
('isWrite', self.isWrite),
|
|
||||||
('file', self.targetFile),
|
|
||||||
('level', record.levelname),
|
|
||||||
('message', record.msg),
|
|
||||||
])
|
])
|
||||||
|
try:
|
||||||
|
data['package'] = inspect.stack()[9][0].f_globals.get('__package__')
|
||||||
|
data['lineno'] = inspect.stack()[9][2]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
data['version'] = self.version
|
||||||
|
data['plugin'] = self.plugin
|
||||||
|
data['time'] = self.timestamp
|
||||||
|
data['isWrite'] = self.isWrite
|
||||||
|
data['file'] = self.targetFile
|
||||||
|
data['level'] = record.levelname
|
||||||
|
data['message'] = record.msg
|
||||||
if not self.plugin:
|
if not self.plugin:
|
||||||
del data['plugin']
|
del data['plugin']
|
||||||
if not self.isWrite:
|
if not self.isWrite:
|
||||||
|
|
Loading…
Reference in a new issue