11import logging
22import os
3+ import sys
34from pathlib import Path
45from typing import Annotated , Any
56
2021
2122from . import __version__
2223from .logging import setup_logging
23- from .utils .cli import get_rich_toolkit , get_uvicorn_log_config
24+ from .utils .cli import (
25+ get_rich_toolkit ,
26+ get_uvicorn_log_config ,
27+ should_use_rich_uvicorn_logs ,
28+ )
2429
2530app = typer .Typer (
2631 rich_markup_mode = "rich" , context_settings = {"help_option_names" : ["-h" , "--help" ]}
@@ -99,7 +104,7 @@ def callback(
99104
100105 log_level = logging .DEBUG if verbose else logging .INFO
101106
102- setup_logging (level = log_level )
107+ setup_logging (level = log_level , use_rich = sys . stderr . isatty () )
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_uvicorn_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