use conf directly isntead of lambda
This commit is contained in:
parent
5394f1763c
commit
fc5d5faaed
3 changed files with 10 additions and 8 deletions
|
@ -256,7 +256,7 @@ def setup_logging(logger: logging.Logger, args: argparse.Namespace, conf: Config
|
||||||
else:
|
else:
|
||||||
logger.getChild('lbry').setLevel(logging.DEBUG)
|
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)
|
loggly_handler.setLevel(logging.ERROR)
|
||||||
logger.getChild('lbry').addHandler(loggly_handler)
|
logger.getChild('lbry').addHandler(loggly_handler)
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,12 @@ import json
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import typing
|
||||||
from aiohttp.client_exceptions import ClientError
|
from aiohttp.client_exceptions import ClientError
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from lbry import utils, __version__
|
from lbry import utils, __version__
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
from lbry.conf import Config
|
||||||
|
|
||||||
LOGGLY_TOKEN = 'BQEzZmMzLJHgAGxkBF00LGD0YGuyATVgAmqxAQEuAQZ2BQH4'
|
LOGGLY_TOKEN = 'BQEzZmMzLJHgAGxkBF00LGD0YGuyATVgAmqxAQEuAQZ2BQH4'
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ class JsonFormatter(logging.Formatter):
|
||||||
|
|
||||||
|
|
||||||
class HTTPSLogglyHandler(logging.Handler):
|
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__()
|
super().__init__()
|
||||||
self.fqdn = fqdn
|
self.fqdn = fqdn
|
||||||
self.localname = localname
|
self.localname = localname
|
||||||
|
@ -47,11 +49,11 @@ class HTTPSLogglyHandler(logging.Handler):
|
||||||
)
|
)
|
||||||
self._loop = asyncio.get_event_loop()
|
self._loop = asyncio.get_event_loop()
|
||||||
self._session = aiohttp.ClientSession()
|
self._session = aiohttp.ClientSession()
|
||||||
self._toggle = feature_toggle
|
self._config: typing.Optional['Config'] = config
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self):
|
def enabled(self):
|
||||||
return self._toggle and self._toggle()
|
return self._config and self._config.share_usage_data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_full_message(record):
|
def get_full_message(record):
|
||||||
|
@ -90,7 +92,7 @@ class HTTPSLogglyHandler(logging.Handler):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_loggly_handler(feature_toggle):
|
def get_loggly_handler(config):
|
||||||
handler = HTTPSLogglyHandler(LOGGLY_TOKEN, feature_toggle=feature_toggle)
|
handler = HTTPSLogglyHandler(LOGGLY_TOKEN, config=config)
|
||||||
handler.setFormatter(JsonFormatter())
|
handler.setFormatter(JsonFormatter())
|
||||||
return handler
|
return handler
|
||||||
|
|
|
@ -29,7 +29,7 @@ class SettingsManagement(CommandTestCase):
|
||||||
# test_privacy_settings (merged for reducing test time, unmerge when its fast)
|
# test_privacy_settings (merged for reducing test time, unmerge when its fast)
|
||||||
# tests that changing share_usage_data propagates to the relevant properties
|
# tests that changing share_usage_data propagates to the relevant properties
|
||||||
self.assertFalse(self.daemon.jsonrpc_settings_get()['share_usage_data'])
|
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.addCleanup(loggly.close)
|
||||||
self.assertFalse(self.daemon.analytics_manager.enabled)
|
self.assertFalse(self.daemon.analytics_manager.enabled)
|
||||||
self.assertFalse(loggly.enabled)
|
self.assertFalse(loggly.enabled)
|
||||||
|
|
Loading…
Reference in a new issue