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 api import Api
from track import Track from track import Track
from manager import Manager 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 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,6 +92,12 @@ 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)
configure_handler(handler, log, level)
return handler
return helper
def configure_handler(handler, log, level):
if handler.name: if handler.name:
remove_handlers(log, handler.name) remove_handlers(log, handler.name)
handler.setLevel(level) handler.setLevel(level)
@ -101,7 +108,6 @@ def _log_decorator(fn):
if log.level > level: if log.level > level:
log.setLevel(level) log.setLevel(level)
return handler return handler
return helper
def disable_third_party_loggers(): def disable_third_party_loggers():
@ -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__

View file

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