forked from LBRYCommunity/lbry-sdk
Merge pull request #383 from lbryio/logging-improvements
Logging Improvements
This commit is contained in:
commit
ddcfa7f97c
1 changed files with 19 additions and 1 deletions
|
@ -10,9 +10,11 @@ import traceback
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests_futures.sessions import FuturesSession
|
from requests_futures.sessions import FuturesSession
|
||||||
|
import twisted.python.log
|
||||||
|
|
||||||
import lbrynet
|
import lbrynet
|
||||||
from lbrynet import analytics
|
from lbrynet import analytics
|
||||||
|
from lbrynet import build_type
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
from lbrynet.core import utils
|
from lbrynet.core import utils
|
||||||
|
|
||||||
|
@ -147,8 +149,14 @@ def get_loggly_url(token=None, version=None):
|
||||||
return LOGGLY_URL.format(token=token, tag='lbrynet-' + version)
|
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
|
@_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()
|
||||||
formatter = JsonFormatter(**kwargs)
|
formatter = JsonFormatter(**kwargs)
|
||||||
handler = HTTPSHandler(url)
|
handler = HTTPSHandler(url)
|
||||||
|
@ -250,6 +258,7 @@ def configure_logging(file_name, console, verbose=None):
|
||||||
See `convert_verbose` for more details.
|
See `convert_verbose` for more details.
|
||||||
"""
|
"""
|
||||||
verbose = convert_verbose(verbose)
|
verbose = convert_verbose(verbose)
|
||||||
|
configure_twisted()
|
||||||
configure_file_handler(file_name)
|
configure_file_handler(file_name)
|
||||||
configure_loggly_handler()
|
configure_loggly_handler()
|
||||||
disable_third_party_loggers()
|
disable_third_party_loggers()
|
||||||
|
@ -270,6 +279,15 @@ def configure_logging(file_name, console, verbose=None):
|
||||||
handler.addFilter(LoggerNameFilter(verbose))
|
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):
|
class LoggerNameFilter(object):
|
||||||
"""Filter a log record based on its name.
|
"""Filter a log record based on its name.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue