diff --git a/lib/daemon.py b/lib/daemon.py index ed846c12d7..3cf465f58f 100644 --- a/lib/daemon.py +++ b/lib/daemon.py @@ -4,6 +4,7 @@ from systemd.daemon import notify # type: ignore +from systemd import journal from uaclient import defaults from uaclient.config import UAConfig from uaclient.daemon import ( @@ -16,12 +17,7 @@ def main() -> int: - setup_logging( - logging.INFO, - logging.DEBUG, - defaults.CONFIG_DEFAULTS["daemon_log_file"], - logger=LOG, - ) + LOG.setLevel(logging.DEBUG) cfg = UAConfig() setup_logging( logging.INFO, logging.DEBUG, log_file=cfg.daemon_log_file, logger=LOG diff --git a/lib/timer.py b/lib/timer.py index 9367e079a9..18f286d34f 100644 --- a/lib/timer.py +++ b/lib/timer.py @@ -6,6 +6,7 @@ from datetime import datetime, timedelta, timezone from typing import Callable, Optional +from systemd import journal from uaclient import defaults from uaclient.cli import setup_logging from uaclient.config import UAConfig @@ -179,25 +180,14 @@ def run_jobs(cfg: UAConfig, current_time: datetime): if __name__ == "__main__": - setup_logging( - logging.CRITICAL, - logging.DEBUG, - defaults.CONFIG_DEFAULTS["timer_log_file"], - logger=LOG, - ) + LOG.setLevel(logging.DEBUG) cfg = UAConfig() current_time = datetime.now(timezone.utc) + LOG.setLevel(logging.DEBUG) - # The ua-timer logger should log everything to its file - setup_logging( - logging.CRITICAL, - logging.DEBUG, - log_file=cfg.timer_log_file, - logger=LOG, - ) # Make sure the ua-timer logger does not generate double logging LOG.propagate = False # The root logger should log any error to the timer log file - setup_logging(logging.CRITICAL, logging.ERROR, log_file=cfg.timer_log_file) + root_logger.setLevel(logging.ERROR) run_jobs(cfg=cfg, current_time=current_time) diff --git a/uaclient/conftest.py b/uaclient/conftest.py index 95ee9a0f39..4b683f44c0 100644 --- a/uaclient/conftest.py +++ b/uaclient/conftest.py @@ -13,8 +13,13 @@ # Those need to be mocked here, before importing our modules, so the pytest # virtualenv doesn't cry because it can't find the modules m_apt_pkg = mock.MagicMock() +m_systemd_pkg = mock.MagicMock() +m_systemd_pkg.journal = mock.MagicMock() +m_systemd_pkg.journal.JournalHandler = mock.MagicMock() +m_systemd_pkg.journal.JournalHandler.level = logging.DEBUG sys.modules["apt"] = mock.MagicMock() sys.modules["apt_pkg"] = m_apt_pkg +sys.modules["systemd"] = m_systemd_pkg # Useless try/except to make flake8 happy \_("/)_/ try: