From 877392b3becaccf1b41a67d47f190a48b0ec10fa Mon Sep 17 00:00:00 2001 From: Olivier Le Thanh Duong Date: Tue, 29 Oct 2024 10:45:36 +0100 Subject: [PATCH] Fix: Log level could not be configured from settings Solution: Add a `LOG_LEVEL` setting defaulting to "WARNING". Replace PR #581 https://github.com/aleph-im/aleph-vm/pull/581 --- src/aleph/vm/conf.py | 1 + src/aleph/vm/orchestrator/cli.py | 9 +++++++-- src/aleph/vm/orchestrator/custom_logs.py | 6 +----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/aleph/vm/conf.py b/src/aleph/vm/conf.py index 9a04d313..cf39a80e 100644 --- a/src/aleph/vm/conf.py +++ b/src/aleph/vm/conf.py @@ -147,6 +147,7 @@ class Settings(BaseSettings): # System logs make boot ~2x slower PRINT_SYSTEM_LOGS = False IGNORE_TRACEBACK_FROM_DIAGNOSTICS = True + LOG_LEVEL = "WARNING" DEBUG_ASYNCIO = False # Networking does not work inside Docker/Podman diff --git a/src/aleph/vm/orchestrator/cli.py b/src/aleph/vm/orchestrator/cli.py index 21712204..7366a083 100644 --- a/src/aleph/vm/orchestrator/cli.py +++ b/src/aleph/vm/orchestrator/cli.py @@ -66,7 +66,7 @@ def parse_args(args): help="set loglevel to INFO", action="store_const", const=logging.INFO, - default=logging.WARNING, + default=settings.LOG_LEVEL, ) parser.add_argument( "-vv", @@ -298,7 +298,12 @@ def main(): ) # log_format = "[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s" - setup_handlers(args, log_format) + handlers = setup_handlers(args, log_format) + logging.basicConfig( + level=args.loglevel, + format=log_format, + handlers=handlers, + ) logging.getLogger("aiosqlite").setLevel(logging.WARNING) logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING) diff --git a/src/aleph/vm/orchestrator/custom_logs.py b/src/aleph/vm/orchestrator/custom_logs.py index 23758bfa..7cb6e982 100644 --- a/src/aleph/vm/orchestrator/custom_logs.py +++ b/src/aleph/vm/orchestrator/custom_logs.py @@ -49,8 +49,4 @@ def setup_handlers(args, log_format): non_execution_handler.setFormatter( logging.Formatter("%(asctime)s | %(levelname)s %(name)s:%(lineno)s | %(message)s ") ) - logging.basicConfig( - level=args.loglevel, - format=log_format, - handlers=[non_execution_handler, execution_handler], - ) + return [non_execution_handler, execution_handler]