2020
2121from . import __version__
2222from .logging import setup_logging
23- from .utils .cli import get_rich_toolkit , get_uvicorn_log_config
23+ from .utils .cli import (
24+ get_rich_toolkit ,
25+ get_uvicorn_log_config ,
26+ should_use_rich_logs ,
27+ )
2428
2529app = typer .Typer (
2630 rich_markup_mode = "rich" , context_settings = {"help_option_names" : ["-h" , "--help" ]}
@@ -99,7 +103,8 @@ def callback(
99103
100104 log_level = logging .DEBUG if verbose else logging .INFO
101105
102- setup_logging (level = log_level )
106+ if should_use_rich_logs ():
107+ setup_logging (level = log_level )
103108
104109
105110def _get_module_tree (module_paths : list [Path ]) -> Tree :
@@ -271,6 +276,10 @@ def _run(
271276 toolkit .print ("Logs:" )
272277 toolkit .print_line ()
273278
279+ extra_uvicorn_kwargs : dict [str , Any ] = {}
280+ if should_use_rich_logs ():
281+ extra_uvicorn_kwargs ["log_config" ] = get_uvicorn_log_config ()
282+
274283 uvicorn .run (
275284 app = import_string ,
276285 host = host ,
@@ -285,7 +294,7 @@ def _run(
285294 root_path = root_path ,
286295 proxy_headers = proxy_headers ,
287296 forwarded_allow_ips = forwarded_allow_ips ,
288- log_config = get_uvicorn_log_config () ,
297+ ** extra_uvicorn_kwargs ,
289298 )
290299
291300
0 commit comments