Merge pull request #207 from lbryio/better-json
Use better json formatting
This commit is contained in:
commit
b360eb6181
2 changed files with 23 additions and 13 deletions
|
@ -112,19 +112,30 @@ def get_loggly_url(token=None, version=None):
|
||||||
@_log_decorator
|
@_log_decorator
|
||||||
def configure_loggly_handler(url=None, **kwargs):
|
def configure_loggly_handler(url=None, **kwargs):
|
||||||
url = url or get_loggly_url()
|
url = url or get_loggly_url()
|
||||||
json_format = {
|
formatter = JsonFormatter(**kwargs)
|
||||||
"loggerName": "%(name)s",
|
|
||||||
"asciTime": "%(asctime)s",
|
|
||||||
"fileName": "%(filename)s",
|
|
||||||
"functionName": "%(funcName)s",
|
|
||||||
"levelNo": "%(levelno)s",
|
|
||||||
"lineNo": "%(lineno)d",
|
|
||||||
"levelName": "%(levelname)s",
|
|
||||||
"message": "%(message)s",
|
|
||||||
}
|
|
||||||
json_format.update(kwargs)
|
|
||||||
formatter = logging.Formatter(json.dumps(json_format))
|
|
||||||
handler = HTTPSHandler(url)
|
handler = HTTPSHandler(url)
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
handler.name = 'loggly'
|
handler.name = 'loggly'
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
|
|
||||||
|
class JsonFormatter(logging.Formatter):
|
||||||
|
"""Format log records using json serialization"""
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
self.attributes = kwargs
|
||||||
|
|
||||||
|
def format(self, record):
|
||||||
|
data = {
|
||||||
|
'loggerName': record.name,
|
||||||
|
'asciTime': self.formatTime(record),
|
||||||
|
'fileName': record.filename,
|
||||||
|
'functionName': record.funcName,
|
||||||
|
'levelNo': record.levelno,
|
||||||
|
'lineNo': record.lineno,
|
||||||
|
'levelName': record.levelname,
|
||||||
|
'message': record.getMessage(),
|
||||||
|
}
|
||||||
|
data.update(self.attributes)
|
||||||
|
if record.exc_info:
|
||||||
|
data['exc_info'] = self.formatException(record.exc_info)
|
||||||
|
return json.dumps(data)
|
||||||
|
|
|
@ -1034,7 +1034,6 @@ class Daemon(jsonrpc.JSONRPC):
|
||||||
session_id=self._session_id
|
session_id=self._session_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _setup_lbry_file_manager(self):
|
def _setup_lbry_file_manager(self):
|
||||||
self.startup_status = STARTUP_STAGES[3]
|
self.startup_status = STARTUP_STAGES[3]
|
||||||
self.lbry_file_metadata_manager = DBEncryptedFileMetadataManager(self.db_dir)
|
self.lbry_file_metadata_manager = DBEncryptedFileMetadataManager(self.db_dir)
|
||||||
|
|
Loading…
Reference in a new issue