Merge pull request #369 from lbryio/track-errors

track errors in analytics
This commit is contained in:
Job Evers‐Meltzer 2016-12-30 15:39:41 -06:00 committed by GitHub
commit 6936dbd588
4 changed files with 34 additions and 10 deletions

View file

@ -3,4 +3,4 @@ from events import *
from api import Api
from track import Track
from manager import Manager
from logging_handler import Handler

View 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)

View file

@ -12,6 +12,7 @@ import requests
from requests_futures.sessions import FuturesSession
import lbrynet
from lbrynet import analytics
from lbrynet import conf
from lbrynet.core import utils
@ -91,19 +92,24 @@ def _log_decorator(fn):
# the numeric level when passed a text level
level = logging.getLevelName(level)
handler = fn(*args, **kwargs)
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)
configure_handler(handler, log, level)
return handler
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():
logging.getLogger('requests').setLevel(logging.WARNING)
logging.getLogger('urllib3').setLevel(logging.WARNING)
@ -129,6 +135,12 @@ def configure_file_handler(file_name, **kwargs):
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):
token = token or utils.deobfuscate(conf.settings.LOGGLY_TOKEN)
version = version or lbrynet.__version__

View file

@ -130,6 +130,7 @@ def start_server_and_listen(launchui, use_auth, analytics_manager):
analytics_manager: to send analytics
"""
analytics_manager.send_server_startup()
log_support.configure_analytics_handler(analytics_manager)
try:
daemon_server = DaemonServer(analytics_manager)
yield daemon_server.start(use_auth)