diff --git a/lbrynet/core/log_support.py b/lbrynet/core/log_support.py index 2f2a5c75b..1fb3979c7 100644 --- a/lbrynet/core/log_support.py +++ b/lbrynet/core/log_support.py @@ -112,19 +112,30 @@ def get_loggly_url(token=None, version=None): @_log_decorator def configure_loggly_handler(url=None, **kwargs): url = url or get_loggly_url() - json_format = { - "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)) + formatter = JsonFormatter(**kwargs) handler = HTTPSHandler(url) handler.setFormatter(formatter) handler.name = 'loggly' 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) diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index a9fb10f0f..fc67a4132 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -1034,7 +1034,6 @@ class Daemon(jsonrpc.JSONRPC): session_id=self._session_id ) - def _setup_lbry_file_manager(self): self.startup_status = STARTUP_STAGES[3] self.lbry_file_metadata_manager = DBEncryptedFileMetadataManager(self.db_dir)