Skip to content

Commit 63eb361

Browse files
authored
Added optional logging configuration. (#159)
1 parent d8699d5 commit 63eb361

File tree

3 files changed

+36
-41
lines changed

3 files changed

+36
-41
lines changed

poetry.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

taskiq/cli/worker/args.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ class WorkerArgs:
2727
modules: List[str]
2828
tasks_pattern: str = "tasks.py"
2929
fs_discover: bool = False
30+
configure_logging: bool = True
3031
log_level: LogLevel = LogLevel.INFO
3132
workers: int = 2
32-
log_collector_format: str = (
33-
"[%(asctime)s][%(levelname)-7s][%(module)s:%(funcName)s:%(lineno)d] %(message)s"
34-
)
3533
max_threadpool_threads: int = 10
3634
no_parse: bool = False
3735
shutdown_timeout: float = 5
@@ -118,18 +116,6 @@ def from_cli( # noqa: WPS213
118116
default=2,
119117
help="Number of worker child processes",
120118
)
121-
parser.add_argument(
122-
"--log-collector-format",
123-
"-lcf",
124-
type=str,
125-
default=(
126-
"[%(asctime)s]"
127-
"[%(levelname)-7s]"
128-
"[%(module)s:%(funcName)s:%(lineno)d] "
129-
"%(message)s"
130-
),
131-
help="Format which is used when collecting logs from function execution",
132-
)
133119
parser.add_argument(
134120
"--no-parse",
135121
action="store_true",
@@ -187,6 +173,12 @@ def from_cli( # noqa: WPS213
187173
default=0,
188174
help="Maximum prefetched tasks per worker process. ",
189175
)
176+
parser.add_argument(
177+
"--no-configure-logging",
178+
action="store_false",
179+
dest="configure_logging",
180+
help="Use this parameter if your application configures custom logging.",
181+
)
190182

191183
namespace = parser.parse_args(args)
192184
return WorkerArgs(**namespace.__dict__)

taskiq/cli/worker/run.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ def run_worker(args: WorkerArgs) -> None: # noqa: WPS213
158158
159159
:raises ValueError: if reload flag is used, but dependencies are not installed.
160160
"""
161-
logging.basicConfig(
162-
level=logging.getLevelName(args.log_level),
163-
format="[%(asctime)s][%(name)s][%(levelname)-7s][%(processName)s] %(message)s",
164-
)
161+
if args.configure_logging:
162+
logging.basicConfig(
163+
level=logging.getLevelName(args.log_level),
164+
format="[%(asctime)s][%(name)s][%(levelname)-7s]"
165+
+ "[%(processName)s] %(message)s",
166+
)
167+
logging.getLogger("taskiq").setLevel(level=logging.getLevelName(args.log_level))
165168
logging.getLogger("watchdog.observers.inotify_buffer").setLevel(level=logging.INFO)
166169
logger.info("Starting %s worker processes.", args.workers)
167170

0 commit comments

Comments
 (0)