From 0ababb7f3b7565b8702b60434831ae5d48dac5bf Mon Sep 17 00:00:00 2001 From: Job Evers Date: Tue, 3 Jan 2017 22:16:57 -0600 Subject: [PATCH 1/2] Route twisted logging messages to the python stdlib logger --- lbrynet/core/log_support.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lbrynet/core/log_support.py b/lbrynet/core/log_support.py index 173f6f198..99c035fbb 100644 --- a/lbrynet/core/log_support.py +++ b/lbrynet/core/log_support.py @@ -10,6 +10,7 @@ import traceback import requests from requests_futures.sessions import FuturesSession +import twisted.python.log import lbrynet from lbrynet import analytics @@ -250,6 +251,7 @@ def configure_logging(file_name, console, verbose=None): See `convert_verbose` for more details. """ verbose = convert_verbose(verbose) + configure_twisted() configure_file_handler(file_name) configure_loggly_handler() disable_third_party_loggers() @@ -270,6 +272,15 @@ def configure_logging(file_name, console, verbose=None): handler.addFilter(LoggerNameFilter(verbose)) +def configure_twisted(): + """Setup twisted logging to output events to the python stdlib logger""" + # I tried using the new logging api + # https://twistedmatrix.com/documents/current/core/howto/logger.html#compatibility-with-standard-library-logging + # and it simply didn't work + observer = twisted.python.log.PythonLoggingObserver() + observer.start() + + class LoggerNameFilter(object): """Filter a log record based on its name. From abc122f77b8c99b8ff4350c7d4ba767721123177 Mon Sep 17 00:00:00 2001 From: Job Evers Date: Tue, 3 Jan 2017 22:17:44 -0600 Subject: [PATCH 2/2] Don't send log messages to loggly in dev mode --- lbrynet/core/log_support.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lbrynet/core/log_support.py b/lbrynet/core/log_support.py index 99c035fbb..b01636d59 100644 --- a/lbrynet/core/log_support.py +++ b/lbrynet/core/log_support.py @@ -14,6 +14,7 @@ import twisted.python.log import lbrynet from lbrynet import analytics +from lbrynet import build_type from lbrynet import conf from lbrynet.core import utils @@ -148,8 +149,14 @@ def get_loggly_url(token=None, version=None): return LOGGLY_URL.format(token=token, tag='lbrynet-' + version) +def configure_loggly_handler(*args, **kwargs): + if build_type.BUILD == 'dev': + return + _configure_loggly_handler(*args, **kwargs) + + @_log_decorator -def configure_loggly_handler(url=None, **kwargs): +def _configure_loggly_handler(url=None, **kwargs): url = url or get_loggly_url() formatter = JsonFormatter(**kwargs) handler = HTTPSHandler(url)