Merge pull request #369 from lbryio/track-errors
track errors in analytics
This commit is contained in:
commit
6936dbd588
4 changed files with 34 additions and 10 deletions
|
@ -3,4 +3,4 @@ from events import *
|
||||||
from api import Api
|
from api import Api
|
||||||
from track import Track
|
from track import Track
|
||||||
from manager import Manager
|
from manager import Manager
|
||||||
|
from logging_handler import Handler
|
||||||
|
|
11
lbrynet/analytics/logging_handler.py
Normal file
11
lbrynet/analytics/logging_handler.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
class Handler(logging.Handler):
|
||||||
|
"""A logging handler that reports errors to the analytics manager"""
|
||||||
|
def __init__(self, manager, level=logging.ERROR):
|
||||||
|
self.manager = manager
|
||||||
|
logging.Handler.__init__(self, level)
|
||||||
|
|
||||||
|
def emit(self, record):
|
||||||
|
self.manager.send_error(record.message)
|
|
@ -12,6 +12,7 @@ import requests
|
||||||
from requests_futures.sessions import FuturesSession
|
from requests_futures.sessions import FuturesSession
|
||||||
|
|
||||||
import lbrynet
|
import lbrynet
|
||||||
|
from lbrynet import analytics
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
from lbrynet.core import utils
|
from lbrynet.core import utils
|
||||||
|
|
||||||
|
@ -91,19 +92,24 @@ def _log_decorator(fn):
|
||||||
# the numeric level when passed a text level
|
# the numeric level when passed a text level
|
||||||
level = logging.getLevelName(level)
|
level = logging.getLevelName(level)
|
||||||
handler = fn(*args, **kwargs)
|
handler = fn(*args, **kwargs)
|
||||||
if handler.name:
|
configure_handler(handler, log, level)
|
||||||
remove_handlers(log, handler.name)
|
|
||||||
handler.setLevel(level)
|
|
||||||
log.addHandler(handler)
|
|
||||||
# need to reduce the logger's level down to the
|
|
||||||
# handler's level or else the handler won't
|
|
||||||
# get those messages
|
|
||||||
if log.level > level:
|
|
||||||
log.setLevel(level)
|
|
||||||
return handler
|
return handler
|
||||||
return helper
|
return helper
|
||||||
|
|
||||||
|
|
||||||
|
def configure_handler(handler, log, level):
|
||||||
|
if handler.name:
|
||||||
|
remove_handlers(log, handler.name)
|
||||||
|
handler.setLevel(level)
|
||||||
|
log.addHandler(handler)
|
||||||
|
# need to reduce the logger's level down to the
|
||||||
|
# handler's level or else the handler won't
|
||||||
|
# get those messages
|
||||||
|
if log.level > level:
|
||||||
|
log.setLevel(level)
|
||||||
|
return handler
|
||||||
|
|
||||||
|
|
||||||
def disable_third_party_loggers():
|
def disable_third_party_loggers():
|
||||||
logging.getLogger('requests').setLevel(logging.WARNING)
|
logging.getLogger('requests').setLevel(logging.WARNING)
|
||||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
||||||
|
@ -129,6 +135,12 @@ def configure_file_handler(file_name, **kwargs):
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
|
|
||||||
|
def configure_analytics_handler(analytics_manager):
|
||||||
|
handler = analytics.Handler(analytics_manager)
|
||||||
|
handler.name = 'analytics'
|
||||||
|
return configure_handler(handler, logging.getLogger(), logging.ERROR)
|
||||||
|
|
||||||
|
|
||||||
def get_loggly_url(token=None, version=None):
|
def get_loggly_url(token=None, version=None):
|
||||||
token = token or utils.deobfuscate(conf.settings.LOGGLY_TOKEN)
|
token = token or utils.deobfuscate(conf.settings.LOGGLY_TOKEN)
|
||||||
version = version or lbrynet.__version__
|
version = version or lbrynet.__version__
|
||||||
|
|
|
@ -130,6 +130,7 @@ def start_server_and_listen(launchui, use_auth, analytics_manager):
|
||||||
analytics_manager: to send analytics
|
analytics_manager: to send analytics
|
||||||
"""
|
"""
|
||||||
analytics_manager.send_server_startup()
|
analytics_manager.send_server_startup()
|
||||||
|
log_support.configure_analytics_handler(analytics_manager)
|
||||||
try:
|
try:
|
||||||
daemon_server = DaemonServer(analytics_manager)
|
daemon_server = DaemonServer(analytics_manager)
|
||||||
yield daemon_server.start(use_auth)
|
yield daemon_server.start(use_auth)
|
||||||
|
|
Loading…
Reference in a new issue