diff --git a/taskiq/cli/worker/process_manager.py b/taskiq/cli/worker/process_manager.py index b5d27427..f27516db 100644 --- a/taskiq/cli/worker/process_manager.py +++ b/taskiq/cli/worker/process_manager.py @@ -271,7 +271,7 @@ def start(self) -> int | None: # noqa: C901 # We bulk_process all pending events. while not self.action_queue.empty(): action = self.action_queue.get() - logging.debug("Got event: %s", action) + logger.debug("Got event: %s", action) if isinstance(action, ReloadAllAction): action.handle( workers_num=len(self.workers), diff --git a/taskiq/cli/worker/run.py b/taskiq/cli/worker/run.py index 1443163d..1144a982 100644 --- a/taskiq/cli/worker/run.py +++ b/taskiq/cli/worker/run.py @@ -211,7 +211,7 @@ def run_worker(args: WorkerArgs) -> int | None: observer = Observer() observer.start() args.workers = 1 - logging.warning( + logger.warning( "Reload on change enabled. Number of worker processes set to 1.", ) diff --git a/tests/cli/worker/test_worker_logging.py b/tests/cli/worker/test_worker_logging.py index d970876e..878ca36b 100644 --- a/tests/cli/worker/test_worker_logging.py +++ b/tests/cli/worker/test_worker_logging.py @@ -120,3 +120,54 @@ def test_worker_process_logs_listening_started( assert wait_for_output(process, "Listening started.") finally: stop(process) + + +@pytest.mark.parametrize("reload", [False, True]) +@pytest.mark.parametrize("configure_logging", [False, True]) +def test_reload_respects_logging_configuration( + reload: bool, + configure_logging: bool, +) -> None: + process = subprocess.run( # noqa: S603 + [ + sys.executable, + "-c", + """ +import logging +import sys +from unittest.mock import patch + +from taskiq.cli.worker.args import WorkerArgs +from taskiq.cli.worker.process_manager import ShutdownAction +from taskiq.cli.worker.run import run_worker + +reload = sys.argv[1] == "True" +configure_logging = sys.argv[2] == "True" +assert not logging.getLogger().handlers +with ( + patch( + "taskiq.cli.worker.process_manager.ProcessManager.prepare_workers", + autospec=True, + ) as prepare_workers, + patch("taskiq.cli.worker.run.Observer"), +): + prepare_workers.side_effect = lambda manager: manager.action_queue.put( + ShutdownAction(), + ) + run_worker(WorkerArgs( + broker="unused:broker", + modules=[], + reload=reload, + configure_logging=configure_logging, + )) +assert bool(logging.getLogger().handlers) == configure_logging +""", + str(reload), + str(configure_logging), + ], + capture_output=True, + text=True, + timeout=STARTUP_TIMEOUT, + check=False, + ) + assert process.returncode == 0, process.stderr