Merge pull request #122 from lbryio/add-debug-logging

Add debug logging
This commit is contained in:
Jack Robison 2016-08-17 01:33:07 -04:00 committed by GitHub
commit c061fe091b
4 changed files with 18 additions and 13 deletions

View file

@ -1,8 +1,2 @@
import logging
log = logging.getLogger(__name__)
logging.getLogger(__name__).addHandler(logging.NullHandler())
log.setLevel(logging.INFO)
__version__ = "0.3.17" __version__ = "0.3.17"
version = tuple(__version__.split('.')) version = tuple(__version__.split('.'))

View file

@ -55,18 +55,28 @@ def _log_decorator(fn):
def helper(*args, **kwargs): def helper(*args, **kwargs):
log = kwargs.pop('log', logging.getLogger()) log = kwargs.pop('log', logging.getLogger())
level = kwargs.pop('level', logging.INFO) level = kwargs.pop('level', logging.INFO)
if not isinstance(level, int):
# despite the name, getLevelName returns
# the numeric level when passed a text level
level = logging.getLevelName(level)
handler = fn(*args, **kwargs) handler = fn(*args, **kwargs)
if handler.name: if handler.name:
remove_handlers(log, handler.name) remove_handlers(log, handler.name)
handler.setLevel(level)
log.addHandler(handler) log.addHandler(handler)
log.setLevel(level) if log.level > level:
log.setLevel(level)
return helper return helper
def disable_noisy_loggers(): def disable_third_party_loggers():
logging.getLogger('requests').setLevel(logging.WARNING) logging.getLogger('requests').setLevel(logging.WARNING)
def disable_noisy_loggers():
logging.getLogger('lbrynet.dht').setLevel(logging.INFO)
@_log_decorator @_log_decorator
def configure_console(**kwargs): def configure_console(**kwargs):
"""Convenience function to configure a logger that outputs to stdout""" """Convenience function to configure a logger that outputs to stdout"""

View file

@ -240,9 +240,9 @@ class Node(object):
known_nodes = {} known_nodes = {}
def log_error(err, n): def log_error(err, n):
log.error("error storing blob_hash %s at %s", binascii.hexlify(blob_hash), str(n)) log.debug("error storing blob_hash %s at %s", binascii.hexlify(blob_hash), str(n))
log.error(err.getErrorMessage()) log.debug(err.getErrorMessage())
log.error(err.getTraceback()) log.debug(err.getTraceback())
def log_success(res): def log_success(res):
log.debug("Response to store request: %s", str(res)) log.debug("Response to store request: %s", str(res))

View file

@ -73,11 +73,12 @@ def start():
parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False) parser.set_defaults(branch=False, launchui=True, logtoconsole=False, quiet=False)
args = parser.parse_args() args = parser.parse_args()
log_support.disable_noisy_loggers()
log_support.configure_file_handler(lbrynet_log) log_support.configure_file_handler(lbrynet_log)
log_support.configure_loggly_handler() log_support.configure_loggly_handler()
if args.logtoconsole: if args.logtoconsole:
log_support.configure_console() log_support.configure_console(level='DEBUG')
log_support.disable_third_party_loggers()
log_support.disable_noisy_loggers()
try: try:
JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running() JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running()