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
|
@profile
|
||||||
def app_run(app_opts: ClanAppOptions) -> int:
|
def app_run(app_opts: ClanAppOptions) -> int:
|
||||||
if app_opts.debug:
|
if app_opts.debug:
|
||||||
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
|
setup_logging(logging.DEBUG)
|
||||||
setup_logging(logging.DEBUG, root_log_name="clan_cli")
|
|
||||||
else:
|
else:
|
||||||
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
|
setup_logging(logging.INFO)
|
||||||
setup_logging(logging.INFO, root_log_name="clan_cli")
|
|
||||||
|
|
||||||
log.debug("Debug mode enabled")
|
log.debug("Debug mode enabled")
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ def pytest_sessionstart(session: pytest.Session) -> None:
|
|||||||
# You can access the session config, items, testsfailed, etc.
|
# You can access the session config, items, testsfailed, etc.
|
||||||
print(f"Session config: {session.config}")
|
print(f"Session config: {session.config}")
|
||||||
|
|
||||||
setup_logging(level="DEBUG")
|
setup_logging(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
# fixture for git_repo
|
# fixture for git_repo
|
||||||
|
|||||||
@@ -452,10 +452,10 @@ def main() -> None:
|
|||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
if debug := getattr(args, "debug", False):
|
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")
|
log.debug("Debug log activated")
|
||||||
else:
|
else:
|
||||||
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
|
setup_logging(logging.INFO)
|
||||||
|
|
||||||
if not hasattr(args, "func"):
|
if not hasattr(args, "func"):
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from clan_cli.colors import AnsiColor, RgbColor, color_by_tuple
|
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})
|
logger.debug(f"{msg} \n{callers_str}", extra={"command_prefix": prefix})
|
||||||
|
|
||||||
|
|
||||||
def setup_logging(
|
def setup_logging(level: int) -> None:
|
||||||
level: Any,
|
root_logger = logging.getLogger()
|
||||||
root_log_name: str = __name__.split(".")[0],
|
root_logger.setLevel(level)
|
||||||
) -> None:
|
|
||||||
# Get the root logger and set its level
|
|
||||||
main_logger = logging.getLogger(root_log_name)
|
|
||||||
main_logger.setLevel(level)
|
|
||||||
|
|
||||||
# Create and add the default handler
|
# Set our formatter handler
|
||||||
default_handler = logging.StreamHandler()
|
default_handler = logging.StreamHandler()
|
||||||
|
|
||||||
# Create and add your custom handler
|
|
||||||
default_handler.setLevel(level)
|
default_handler.setLevel(level)
|
||||||
trace_prints = bool(int(os.environ.get("TRACE_PRINT", "0")))
|
trace_prints = bool(int(os.environ.get("TRACE_PRINT", "0")))
|
||||||
default_handler.setFormatter(PrefixFormatter(trace_prints))
|
default_handler.setFormatter(PrefixFormatter(trace_prints))
|
||||||
main_logger.addHandler(default_handler)
|
root_logger.addHandler(default_handler)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from clan_cli.custom_logger import setup_logging
|
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.
|
# You can access the session config, items, testsfailed, etc.
|
||||||
print(f"Session config: {session.config}")
|
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()
|
options = options.end().unpack()
|
||||||
|
|
||||||
if "debug" in options and self.window is None:
|
if "debug" in options and self.window is None:
|
||||||
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
|
setup_logging(logging.DEBUG)
|
||||||
setup_logging(logging.DEBUG, root_log_name="clan_cli")
|
|
||||||
elif self.window is None:
|
elif self.window is None:
|
||||||
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
|
setup_logging(logging.INFO)
|
||||||
log.debug("Debug logging enabled")
|
log.debug("Debug logging enabled")
|
||||||
|
|
||||||
if "debug" in options:
|
if "debug" in options:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -27,7 +28,7 @@ def pytest_sessionstart(session: pytest.Session) -> None:
|
|||||||
# You can access the session config, items, testsfailed, etc.
|
# You can access the session config, items, testsfailed, etc.
|
||||||
print(f"Session config: {session.config}")
|
print(f"Session config: {session.config}")
|
||||||
|
|
||||||
setup_logging(level="DEBUG")
|
setup_logging(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
# fixture for git_repo
|
# fixture for git_repo
|
||||||
|
|||||||
Reference in New Issue
Block a user