forked from LBRYCommunity/lbry-sdk
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 track import Track
|
||||
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
|
||||
|
||||
import lbrynet
|
||||
from lbrynet import analytics
|
||||
from lbrynet import conf
|
||||
from lbrynet.core import utils
|
||||
|
||||
|
@ -91,6 +92,12 @@ def _log_decorator(fn):
|
|||
# the numeric level when passed a text level
|
||||
level = logging.getLevelName(level)
|
||||
handler = fn(*args, **kwargs)
|
||||
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)
|
||||
|
@ -101,7 +108,6 @@ def _log_decorator(fn):
|
|||
if log.level > level:
|
||||
log.setLevel(level)
|
||||
return handler
|
||||
return helper
|
||||
|
||||
|
||||
def disable_third_party_loggers():
|
||||
|
@ -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__
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue