wallet server error logging with loggly enabled by LOGGLY_TOKEN
env variable
This commit is contained in:
parent
9b0a99b161
commit
9b3f7e133b
4 changed files with 21 additions and 22 deletions
|
@ -12,11 +12,13 @@ import aiohttp
|
|||
from aiohttp.web import GracefulExit
|
||||
from docopt import docopt
|
||||
|
||||
from torba.loggly_handler import get_loggly_handler
|
||||
from lbry import __version__ as lbrynet_version
|
||||
from lbry.extras.daemon.loggly_handler import get_loggly_handler
|
||||
from lbry.conf import Config, CLIConfig
|
||||
from lbry.extras.daemon.Daemon import Daemon
|
||||
|
||||
LOGGLY_TOKEN = 'BQEzZmMzLJHgAGxkBF00LGD0YGuyATVgAmqxAQEuAQZ2BQH4'
|
||||
|
||||
log = logging.getLogger('lbry')
|
||||
|
||||
|
||||
|
@ -248,9 +250,7 @@ def setup_logging(logger: logging.Logger, args: argparse.Namespace, conf: Config
|
|||
logger.getChild('lbry').setLevel(logging.DEBUG)
|
||||
|
||||
if conf.share_usage_data:
|
||||
loggly_handler = get_loggly_handler()
|
||||
loggly_handler.setLevel(logging.ERROR)
|
||||
logger.getChild('lbry').addHandler(loggly_handler)
|
||||
logger.getChild('lbry').addHandler(get_loggly_handler(f'lbrynet-{lbrynet_version}', LOGGLY_TOKEN))
|
||||
|
||||
|
||||
def run_daemon(args: argparse.Namespace, conf: Config):
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
import asyncio
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
import json
|
||||
import codecs
|
||||
import base64
|
||||
import logging.handlers
|
||||
import traceback
|
||||
import aiohttp
|
||||
from lbry import utils, __version__
|
||||
from aiohttp.client_exceptions import ClientError
|
||||
|
||||
|
||||
LOGGLY_TOKEN = 'BQEzZmMzLJHgAGxkBF00LGD0YGuyATVgAmqxAQEuAQZ2BQH4'
|
||||
def deobfuscate(obfustacated):
|
||||
return base64.b64decode(codecs.encode(obfustacated, 'rot_13')(obfustacated)).decode()
|
||||
|
||||
|
||||
class JsonFormatter(logging.Formatter):
|
||||
"""Format log records using json serialization"""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
self.attributes = kwargs
|
||||
|
||||
def format(self, record):
|
||||
def format(self, record: logging.LogRecord):
|
||||
data = {
|
||||
'loggerName': record.name,
|
||||
'asciTime': self.formatTime(record),
|
||||
|
@ -34,23 +36,15 @@ class JsonFormatter(logging.Formatter):
|
|||
|
||||
|
||||
class HTTPSLogglyHandler(logging.Handler):
|
||||
def __init__(self, loggly_token: str, fqdn=False, localname=None, facility=None, cookies=None):
|
||||
def __init__(self, loggly_token: str, tag: str, fqdn=False, localname=None, facility=None, cookies=None):
|
||||
super().__init__()
|
||||
self.fqdn = fqdn
|
||||
self.localname = localname
|
||||
self.facility = facility
|
||||
self.cookies = cookies or {}
|
||||
self.url = "https://logs-01.loggly.com/inputs/{token}/tag/{tag}".format(
|
||||
token=utils.deobfuscate(loggly_token), tag='lbrynet-' + __version__
|
||||
)
|
||||
self.url = f"https://logs-01.loggly.com/inputs/{deobfuscate(loggly_token)}/tag/{tag}"
|
||||
self._loop = asyncio.get_event_loop()
|
||||
self._session = aiohttp.ClientSession()
|
||||
|
||||
def get_full_message(self, record):
|
||||
if record.exc_info:
|
||||
return '\n'.join(traceback.format_exception(*record.exc_info))
|
||||
else:
|
||||
return record.getMessage()
|
||||
self._session = aiohttp.ClientSession(loop=self._loop)
|
||||
|
||||
async def _emit(self, record, retry=True):
|
||||
data = self.format(record).encode()
|
||||
|
@ -76,7 +70,8 @@ class HTTPSLogglyHandler(logging.Handler):
|
|||
pass
|
||||
|
||||
|
||||
def get_loggly_handler():
|
||||
handler = HTTPSLogglyHandler(LOGGLY_TOKEN)
|
||||
def get_loggly_handler(tag: str, token: str, level=logging.ERROR) -> HTTPSLogglyHandler:
|
||||
handler = HTTPSLogglyHandler(token, tag)
|
||||
handler.setFormatter(JsonFormatter())
|
||||
handler.setLevel(level)
|
||||
return handler
|
||||
|
|
|
@ -29,6 +29,7 @@ class Env:
|
|||
pass
|
||||
|
||||
def __init__(self, coin=None):
|
||||
self.loggly_token = self.default('LOGGLY_TOKEN', '')
|
||||
self.logger = class_logger(__name__, self.__class__.__name__)
|
||||
self.allow_root = self.boolean('ALLOW_ROOT', False)
|
||||
self.host = self.default('HOST', 'localhost')
|
||||
|
|
|
@ -4,6 +4,7 @@ import asyncio
|
|||
from concurrent.futures.thread import ThreadPoolExecutor
|
||||
|
||||
import torba
|
||||
from torba.loggly_handler import get_loggly_handler
|
||||
from torba.server.mempool import MemPool, MemPoolAPI
|
||||
|
||||
|
||||
|
@ -67,6 +68,8 @@ class Server:
|
|||
def __init__(self, env):
|
||||
self.env = env
|
||||
self.log = logging.getLogger(__name__).getChild(self.__class__.__name__)
|
||||
if self.env.loggly_token:
|
||||
self.log.addHandler(get_loggly_handler('wallet-server', self.env.loggly_token))
|
||||
self.shutdown_event = asyncio.Event()
|
||||
self.cancellable_tasks = []
|
||||
|
||||
|
|
Loading…
Reference in a new issue