Skip to content

Commit ed4700e

Browse files
committed
add support for custom --log-config
1 parent 46bfd94 commit ed4700e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/fastapi_cli/cli.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def _run(
112112
entrypoint: str | None = None,
113113
proxy_headers: bool = False,
114114
forwarded_allow_ips: str | None = None,
115+
log_config: str | None = None,
115116
) -> None:
116117
with get_rich_toolkit() as toolkit:
117118
server_type = "development" if command == "dev" else "production"
@@ -215,6 +216,9 @@ def _run(
215216
toolkit.print("Logs:")
216217
toolkit.print_line()
217218

219+
if not log_config:
220+
log_config = get_uvicorn_log_config()
221+
218222
uvicorn.run(
219223
app=import_string,
220224
host=host,
@@ -229,7 +233,7 @@ def _run(
229233
root_path=root_path,
230234
proxy_headers=proxy_headers,
231235
forwarded_allow_ips=forwarded_allow_ips,
232-
log_config=get_uvicorn_log_config(),
236+
log_config=log_config,
233237
)
234238

235239

@@ -299,6 +303,13 @@ def dev(
299303
help="Comma separated list of IP Addresses to trust with proxy headers. The literal '*' means trust everything."
300304
),
301305
] = None,
306+
log_config: Annotated[
307+
str | None,
308+
typer.Option(
309+
"--log-config",
310+
help="Path to uvicorn log config yaml or json format, read more at [link=https://uvicorn.dev/settings/#logging]https://uvicorn.dev/settings/#logging[/link]."
311+
),
312+
] = None,
302313
) -> Any:
303314
"""
304315
Run a [bold]FastAPI[/bold] app in [yellow]development[/yellow] mode. 🧪
@@ -337,6 +348,7 @@ def dev(
337348
command="dev",
338349
proxy_headers=proxy_headers,
339350
forwarded_allow_ips=forwarded_allow_ips,
351+
log_config=log_config,
340352
)
341353

342354

@@ -406,6 +418,13 @@ def run(
406418
help="Comma separated list of IP Addresses to trust with proxy headers. The literal '*' means trust everything."
407419
),
408420
] = None,
421+
log_config: Annotated[
422+
str | None,
423+
typer.Option(
424+
"--log-config",
425+
help="Path to uvicorn log config yaml or json format, read more at [link=https://uvicorn.dev/settings/#logging]https://uvicorn.dev/settings/#logging[/link]."
426+
),
427+
] = None,
409428
) -> Any:
410429
"""
411430
Run a [bold]FastAPI[/bold] app in [green]production[/green] mode. 🚀
@@ -444,6 +463,7 @@ def run(
444463
command="run",
445464
proxy_headers=proxy_headers,
446465
forwarded_allow_ips=forwarded_allow_ips,
466+
log_config=log_config,
447467
)
448468

449469

0 commit comments

Comments
 (0)