Skip to content

fix: log configuring when running under spawn and add --log-format #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: log configuring when running under spawn and add --log-format
Fixed issue with logging configuration when using multiprocessing 'spawn' method on macOS.
The spawn method reimports all modules which caused logging configuration to be lost.
Added `--log-format` argument to easily customize logging format across all processes,
including spawned child processes.
  • Loading branch information
Ilya Volnistov committed Mar 25, 2025
commit 49875a6584f8b969e160237572c2a0a1f193299b
6 changes: 6 additions & 0 deletions taskiq/cli/worker/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WorkerArgs:
fs_discover: bool = False
configure_logging: bool = True
log_level: LogLevel = LogLevel.INFO
log_format: str = "[%(asctime)s][%(name)s][%(levelname)-7s][%(processName)s] %(message)s"
workers: int = 2
max_threadpool_threads: Optional[int] = None
max_process_pool_processes: Optional[int] = None
Expand Down Expand Up @@ -118,6 +119,11 @@ def from_cli(
choices=[level.name for level in LogLevel],
help="worker log level",
)
parser.add_argument(
"--log-format",
default="[%(asctime)s][%(name)s][%(levelname)-7s][%(processName)s] %(message)s",
help="worker log format",
)
parser.add_argument(
"--workers",
"-w",
Expand Down
11 changes: 7 additions & 4 deletions taskiq/cli/worker/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import signal
import sys
from concurrent.futures import Executor, ProcessPoolExecutor, ThreadPoolExecutor
from multiprocessing import set_start_method
from multiprocessing import set_start_method, get_start_method
from sys import platform
from typing import Any, Optional, Type

Expand Down Expand Up @@ -86,7 +86,11 @@ def start_listen(args: WorkerArgs) -> None:
"""
shutdown_event = asyncio.Event()
hardkill_counter = 0

if args.configure_logging and get_start_method() == "spawn":
logging.basicConfig(
level=logging.getLevelName(args.log_level),
format=args.log_format,
)
def interrupt_handler(signum: int, _frame: Any) -> None:
"""
Signal handler.
Expand Down Expand Up @@ -186,8 +190,7 @@ def run_worker(args: WorkerArgs) -> Optional[int]:
if args.configure_logging:
logging.basicConfig(
level=logging.getLevelName(args.log_level),
format="[%(asctime)s][%(name)s][%(levelname)-7s]"
"[%(processName)s] %(message)s",
format=args.log_format,
)
logging.getLogger("taskiq").setLevel(level=logging.getLevelName(args.log_level))
logging.getLogger("watchdog.observers.inotify_buffer").setLevel(level=logging.INFO)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy