This commit is contained in:
Miroslav Kovar 2019-10-05 20:44:14 +02:00 committed by Lex Berezhny
parent 63447d1ec3
commit 19e8b6e11f
2 changed files with 31 additions and 3 deletions

View file

@ -221,7 +221,7 @@ def ensure_directory_exists(path: str):
pathlib.Path(path).mkdir(parents=True, exist_ok=True) pathlib.Path(path).mkdir(parents=True, exist_ok=True)
def run_daemon(args: list, conf: Config): def setup_logging(args: argparse.Namespace, conf: Config, loop: asyncio.AbstractEventLoop):
default_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s") default_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
file_handler = logging.handlers.RotatingFileHandler( file_handler = logging.handlers.RotatingFileHandler(
conf.log_file_path, maxBytes=2097152, backupCount=5 conf.log_file_path, maxBytes=2097152, backupCount=5
@ -240,8 +240,6 @@ def run_daemon(args: list, conf: Config):
logging.getLogger('aioupnp').setLevel(logging.WARNING) logging.getLogger('aioupnp').setLevel(logging.WARNING)
logging.getLogger('aiohttp').setLevel(logging.CRITICAL) logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
loop = asyncio.get_event_loop()
log.setLevel(logging.INFO) log.setLevel(logging.INFO)
if args.verbose is not None: if args.verbose is not None:
loop.set_debug(True) loop.set_debug(True)
@ -256,6 +254,10 @@ def run_daemon(args: list, conf: Config):
loggly_handler.setLevel(logging.ERROR) loggly_handler.setLevel(logging.ERROR)
log.addHandler(loggly_handler) log.addHandler(loggly_handler)
def run_daemon(args: argparse.Namespace, conf: Config):
loop = asyncio.get_event_loop()
setup_logging(args, conf, loop)
daemon = Daemon(conf) daemon = Daemon(conf)
def __exit(): def __exit():

View file

@ -1,4 +1,6 @@
import contextlib import contextlib
import asyncio
import logging
from io import StringIO from io import StringIO
from torba.testcase import AsyncioTestCase from torba.testcase import AsyncioTestCase
@ -37,3 +39,27 @@ class CLIIntegrationTest(AsyncioTestCase):
cli.main(["--api", "localhost:5299", "status"]) cli.main(["--api", "localhost:5299", "status"])
actual_output = actual_output.getvalue() actual_output = actual_output.getvalue()
self.assertIn("connection_status", actual_output) self.assertIn("connection_status", actual_output)
def test_setup_logging(self):
def setup(argv):
parser = cli.get_argument_parser()
args, command_args = parser.parse_known_args(argv)
loop = asyncio.get_event_loop()
conf = Config.create_from_arguments(args)
cli.setup_logging(args, conf, loop)
setup(["start"])
self.assertTrue(logging.getLogger("lbry").isEnabledFor(logging.INFO))
self.assertFalse(logging.getLogger("lbry").isEnabledFor(logging.DEBUG))
setup(["start", "--verbose"])
self.assertTrue(logging.getLogger("lbry").isEnabledFor(logging.DEBUG))
self.assertTrue(logging.getLogger("lbry").isEnabledFor(logging.INFO))
self.assertFalse(logging.getLogger("torba").isEnabledFor(logging.DEBUG))
setup(["start", "--verbose", "lbry.extras", "lbry.wallet", "torba.client"])
self.assertTrue(logging.getLogger("lbry.extras").isEnabledFor(logging.DEBUG))
self.assertTrue(logging.getLogger("lbry.wallet").isEnabledFor(logging.DEBUG))
self.assertTrue(logging.getLogger("torba.client").isEnabledFor(logging.DEBUG))
self.assertFalse(logging.getLogger("lbry").isEnabledFor(logging.DEBUG))
self.assertFalse(logging.getLogger("torba").isEnabledFor(logging.DEBUG))