fix logger no longer applying to clan_lib
with moving code to clan_lib we are missing logging for some output. To fix this we remove the module scoping from the logger and just set one global logger.
This commit is contained in:
@@ -23,11 +23,9 @@ class ClanAppOptions:
|
||||
@profile
|
||||
def app_run(app_opts: ClanAppOptions) -> int:
|
||||
if app_opts.debug:
|
||||
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
|
||||
setup_logging(logging.DEBUG, root_log_name="clan_cli")
|
||||
setup_logging(logging.DEBUG)
|
||||
else:
|
||||
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
|
||||
setup_logging(logging.INFO, root_log_name="clan_cli")
|
||||
setup_logging(logging.INFO)
|
||||
|
||||
log.debug("Debug mode enabled")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
@@ -22,7 +23,7 @@ def pytest_sessionstart(session: pytest.Session) -> None:
|
||||
# You can access the session config, items, testsfailed, etc.
|
||||
print(f"Session config: {session.config}")
|
||||
|
||||
setup_logging(level="DEBUG")
|
||||
setup_logging(logging.DEBUG)
|
||||
|
||||
|
||||
# fixture for git_repo
|
||||
|
||||
@@ -452,10 +452,10 @@ def main() -> None:
|
||||
parser.print_help()
|
||||
|
||||
if debug := getattr(args, "debug", False):
|
||||
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
|
||||
setup_logging(logging.DEBUG)
|
||||
log.debug("Debug log activated")
|
||||
else:
|
||||
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
|
||||
setup_logging(logging.INFO)
|
||||
|
||||
if not hasattr(args, "func"):
|
||||
return
|
||||
|
||||
@@ -3,7 +3,6 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from clan_cli.colors import AnsiColor, RgbColor, color_by_tuple
|
||||
|
||||
@@ -153,19 +152,13 @@ def print_trace(msg: str, logger: logging.Logger, prefix: str | None) -> None:
|
||||
logger.debug(f"{msg} \n{callers_str}", extra={"command_prefix": prefix})
|
||||
|
||||
|
||||
def setup_logging(
|
||||
level: Any,
|
||||
root_log_name: str = __name__.split(".")[0],
|
||||
) -> None:
|
||||
# Get the root logger and set its level
|
||||
main_logger = logging.getLogger(root_log_name)
|
||||
main_logger.setLevel(level)
|
||||
def setup_logging(level: int) -> None:
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(level)
|
||||
|
||||
# Create and add the default handler
|
||||
# Set our formatter handler
|
||||
default_handler = logging.StreamHandler()
|
||||
|
||||
# Create and add your custom handler
|
||||
default_handler.setLevel(level)
|
||||
trace_prints = bool(int(os.environ.get("TRACE_PRINT", "0")))
|
||||
default_handler.setFormatter(PrefixFormatter(trace_prints))
|
||||
main_logger.addHandler(default_handler)
|
||||
root_logger.addHandler(default_handler)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
from clan_cli.custom_logger import setup_logging
|
||||
|
||||
@@ -19,4 +21,4 @@ def pytest_sessionstart(session: pytest.Session) -> None:
|
||||
# You can access the session config, items, testsfailed, etc.
|
||||
print(f"Session config: {session.config}")
|
||||
|
||||
setup_logging(level="INFO")
|
||||
setup_logging(logging.DEBUG)
|
||||
|
||||
@@ -71,10 +71,9 @@ class MainApplication(Adw.Application):
|
||||
options = options.end().unpack()
|
||||
|
||||
if "debug" in options and self.window is None:
|
||||
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
|
||||
setup_logging(logging.DEBUG, root_log_name="clan_cli")
|
||||
setup_logging(logging.DEBUG)
|
||||
elif self.window is None:
|
||||
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
|
||||
setup_logging(logging.INFO)
|
||||
log.debug("Debug logging enabled")
|
||||
|
||||
if "debug" in options:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@@ -27,7 +28,7 @@ def pytest_sessionstart(session: pytest.Session) -> None:
|
||||
# You can access the session config, items, testsfailed, etc.
|
||||
print(f"Session config: {session.config}")
|
||||
|
||||
setup_logging(level="DEBUG")
|
||||
setup_logging(logging.DEBUG)
|
||||
|
||||
|
||||
# fixture for git_repo
|
||||
|
||||
Reference in New Issue
Block a user