From fc5d5faaedaf97f05913277b1c582f45ed6018b9 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 20 Feb 2020 14:27:39 -0300 Subject: [PATCH] use conf directly isntead of lambda --- lbry/extras/cli.py | 2 +- lbry/extras/daemon/loggly_handler.py | 14 ++++++++------ tests/integration/other/test_other_commands.py | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lbry/extras/cli.py b/lbry/extras/cli.py index 5752286f8..e5de48616 100644 --- a/lbry/extras/cli.py +++ b/lbry/extras/cli.py @@ -256,7 +256,7 @@ def setup_logging(logger: logging.Logger, args: argparse.Namespace, conf: Config else: logger.getChild('lbry').setLevel(logging.DEBUG) - loggly_handler = get_loggly_handler(lambda: conf.share_usage_data) + loggly_handler = get_loggly_handler(conf) loggly_handler.setLevel(logging.ERROR) logger.getChild('lbry').addHandler(loggly_handler) diff --git a/lbry/extras/daemon/loggly_handler.py b/lbry/extras/daemon/loggly_handler.py index 6d78e2f37..3feb7f766 100644 --- a/lbry/extras/daemon/loggly_handler.py +++ b/lbry/extras/daemon/loggly_handler.py @@ -3,10 +3,12 @@ import json import logging.handlers import traceback +import typing from aiohttp.client_exceptions import ClientError import aiohttp from lbry import utils, __version__ - +if typing.TYPE_CHECKING: + from lbry.conf import Config LOGGLY_TOKEN = 'BQEzZmMzLJHgAGxkBF00LGD0YGuyATVgAmqxAQEuAQZ2BQH4' @@ -36,7 +38,7 @@ class JsonFormatter(logging.Formatter): class HTTPSLogglyHandler(logging.Handler): - def __init__(self, loggly_token: str, fqdn=False, localname=None, facility=None, cookies=None, feature_toggle=None): + def __init__(self, loggly_token: str, fqdn=False, localname=None, facility=None, cookies=None, config=None): super().__init__() self.fqdn = fqdn self.localname = localname @@ -47,11 +49,11 @@ class HTTPSLogglyHandler(logging.Handler): ) self._loop = asyncio.get_event_loop() self._session = aiohttp.ClientSession() - self._toggle = feature_toggle + self._config: typing.Optional['Config'] = config @property def enabled(self): - return self._toggle and self._toggle() + return self._config and self._config.share_usage_data @staticmethod def get_full_message(record): @@ -90,7 +92,7 @@ class HTTPSLogglyHandler(logging.Handler): pass -def get_loggly_handler(feature_toggle): - handler = HTTPSLogglyHandler(LOGGLY_TOKEN, feature_toggle=feature_toggle) +def get_loggly_handler(config): + handler = HTTPSLogglyHandler(LOGGLY_TOKEN, config=config) handler.setFormatter(JsonFormatter()) return handler diff --git a/tests/integration/other/test_other_commands.py b/tests/integration/other/test_other_commands.py index 6cdc3cf07..4ba5b9f10 100644 --- a/tests/integration/other/test_other_commands.py +++ b/tests/integration/other/test_other_commands.py @@ -29,7 +29,7 @@ class SettingsManagement(CommandTestCase): # test_privacy_settings (merged for reducing test time, unmerge when its fast) # tests that changing share_usage_data propagates to the relevant properties self.assertFalse(self.daemon.jsonrpc_settings_get()['share_usage_data']) - loggly = get_loggly_handler(lambda: self.daemon.conf.share_usage_data) + loggly = get_loggly_handler(self.daemon.conf) self.addCleanup(loggly.close) self.assertFalse(self.daemon.analytics_manager.enabled) self.assertFalse(loggly.enabled)