mirror of
https://github.com/nirvana-7777/script.service.ultimate.git
synced 2026-10-01 13:32:15 +02:00
Resolve the standalone log level from ULTIMATE_DEBUG or debug_mode
In standalone mode StandardLogger calls setLevel(logging.DEBUG) unconditionally, so neither the ULTIMATE_DEBUG environment variable nor debug_mode in config.json has any effect and every deployment logs at DEBUG. That is a lot of noise for a service that otherwise runs unattended, and it makes the real warnings hard to find in the container log. Resolve the level instead: ULTIMATE_DEBUG first, then debug_mode, defaulting to INFO. The Kodi-addon path is untouched, since Kodi controls the level there.
This commit is contained in:
@@ -14,6 +14,35 @@ from .environment import get_environment_manager
|
||||
_env_manager_instance = get_environment_manager()
|
||||
|
||||
|
||||
def _resolve_log_level() -> int:
|
||||
"""
|
||||
Log level for the standalone logger.
|
||||
|
||||
The environment variable wins, because that is how a container is
|
||||
configured, then config.json. Anything else defaults to INFO. Level DEBUG
|
||||
logs every upstream request and response and is written to the log file in
|
||||
profile_path as well, so it should only be active when it was actually
|
||||
asked for.
|
||||
"""
|
||||
import os
|
||||
|
||||
env_debug = os.environ.get("ULTIMATE_DEBUG")
|
||||
if env_debug is not None and env_debug.strip() != "":
|
||||
return (
|
||||
logging.DEBUG
|
||||
if env_debug.strip().lower() in ("1", "true", "yes", "on")
|
||||
else logging.INFO
|
||||
)
|
||||
|
||||
try:
|
||||
if _env_manager_instance.get_config("debug_mode", False):
|
||||
return logging.DEBUG
|
||||
except Exception: # noqa: BLE001 - config is optional, never fail logging setup
|
||||
pass
|
||||
|
||||
return logging.INFO
|
||||
|
||||
|
||||
class BaseLogger:
|
||||
"""Base logger interface that all logger implementations must follow"""
|
||||
|
||||
@@ -141,7 +170,7 @@ def create_logger() -> BaseLogger:
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
self._logger.setLevel(logging.DEBUG)
|
||||
self._logger.setLevel(_resolve_log_level())
|
||||
|
||||
def debug(self, message: str) -> None:
|
||||
self._logger.debug(message)
|
||||
|
||||
Reference in New Issue
Block a user