diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 466c477ea..eb36b2e69 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -58,3 +58,5 @@ CURRENCIES = { 'LBC': {'type': 'crypto'}, 'USD': {'type': 'fiat'}, } + +LOGGLY_TOKEN = 'YWRmNGU4NmEtNjkwNC00YjM2LTk3ZjItMGZhODM3ZDhkYzBi' diff --git a/lbrynet/core/log_support.py b/lbrynet/core/log_support.py index 4523b4929..78e9c03f0 100644 --- a/lbrynet/core/log_support.py +++ b/lbrynet/core/log_support.py @@ -1,10 +1,18 @@ +import base64 +import json import logging import logging.handlers import sys +import loggly.handlers + +import lbrynet +from lbrynet import conf + DEFAULT_FORMAT = "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s" DEFAULT_FORMATTER = logging.Formatter(DEFAULT_FORMAT) +LOGGLY_URL = "https://logs-01.loggly.com/inputs/{token}/tag/{tag}" def remove_handlers(log, handler_name): @@ -44,3 +52,30 @@ def configure_file_handler(file_name, **kwargs): handler.setFormatter(DEFAULT_FORMATTER) handler.name = 'file' return handler + + +def get_loggly_url(token=None, version=None): + token = token or base64.b64decode(conf.LOGGLY_TOKEN) + version = version or lbrynet.__version__ + return LOGGLY_URL.format(token=token, tag='lbrynet-' + version) + + +@_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)) + handler = loggly.handlers.HTTPSHandler(url) + handler.setFormatter(formatter) + handler.name = 'loggly' + return handler diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index 08bd27d3a..093c0704b 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -42,6 +42,7 @@ from lbrynet.lbrynet_daemon.LBRYDownloader import GetStream from lbrynet.lbrynet_daemon.LBRYPublisher import Publisher from lbrynet.lbrynet_daemon.LBRYExchangeRateManager import ExchangeRateManager from lbrynet.lbrynet_daemon.Lighthouse import LighthouseClient +from lbrynet.core import log_support from lbrynet.core import utils from lbrynet.core.LBRYMetadata import verify_name_characters from lbrynet.core.utils import generate_id @@ -932,6 +933,7 @@ class LBRYDaemon(jsonrpc.JSONRPC): d = self.settings.start() d.addCallback(lambda _: self.settings.get_lbryid()) d.addCallback(self._set_lbryid) + d.addCallback(lambda _: self._modify_loggly_formatter()) return d def _set_lbryid(self, lbryid): @@ -947,6 +949,14 @@ class LBRYDaemon(jsonrpc.JSONRPC): d = self.settings.save_lbryid(self.lbryid) return d + def _modify_loggly_formatter(self): + session_id = base58.b58encode(generate_id()) + log_support.configure_loggly_handler( + lbry_id=base58.b58encode(self.lbryid), + session_id=session_id + ) + + def _setup_lbry_file_manager(self): self.startup_status = STARTUP_STAGES[3] self.lbry_file_metadata_manager = DBLBRYFileMetadataManager(self.db_dir) diff --git a/lbrynet/lbrynet_daemon/LBRYDaemonControl.py b/lbrynet/lbrynet_daemon/LBRYDaemonControl.py index 66ec51a33..507b3c168 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemonControl.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemonControl.py @@ -76,6 +76,7 @@ def start(): log_support.disable_noisy_loggers() log_support.configure_file_handler(lbrynet_log) + log_support.configure_loggly_handler() if args.logtoconsole: log_support.configure_console()