@@ -199,11 +199,13 @@ def serve_directory(
199
199
200
200
import anyio
201
201
import uvicorn
202
+ from uvicorn .config import LOGGING_CONFIG
202
203
203
204
from ..client import from_uri as client_from_uri
204
205
205
206
print_admin_api_key_if_generated (web_app , host = host , port = port , force = generated )
206
- config = uvicorn .Config (web_app , host = host , port = port )
207
+ log_config = log_config or LOGGING_CONFIG # fall back to uvicorn default
208
+ config = uvicorn .Config (web_app , host = host , port = port , log_config = log_config )
207
209
server = uvicorn .Server (config )
208
210
209
211
async def run_server ():
@@ -334,6 +336,9 @@ def serve_catalog(
334
336
"This verifies that the configuration is compatible with scaled (multi-process) deployments."
335
337
),
336
338
),
339
+ log_config : Optional [str ] = typer .Option (
340
+ None , help = "Custom uvicorn logging configuration file"
341
+ ),
337
342
):
338
343
"Serve a catalog."
339
344
import urllib .parse
@@ -432,8 +437,10 @@ def serve_catalog(
432
437
print_admin_api_key_if_generated (web_app , host = host , port = port )
433
438
434
439
import uvicorn
440
+ from uvicorn .config import LOGGING_CONFIG
435
441
436
- uvicorn .run (web_app , host = host , port = port )
442
+ log_config = log_config or LOGGING_CONFIG # fall back to uvicorn default
443
+ uvicorn .run (web_app , host = host , port = port , log_config = log_config )
437
444
438
445
439
446
serve_app .command ("catalog" )(serve_catalog )
@@ -477,6 +484,9 @@ def serve_pyobject(
477
484
"This verifies that the configuration is compatible with scaled (multi-process) deployments."
478
485
),
479
486
),
487
+ log_config : Optional [str ] = typer .Option (
488
+ None , help = "Custom uvicorn logging configuration file"
489
+ ),
480
490
):
481
491
"Serve a Tree instance from a Python module."
482
492
from ..server .app import build_app , print_admin_api_key_if_generated
@@ -496,8 +506,10 @@ def serve_pyobject(
496
506
print_admin_api_key_if_generated (web_app , host = host , port = port )
497
507
498
508
import uvicorn
509
+ from uvicorn .config import LOGGING_CONFIG
499
510
500
- uvicorn .run (web_app , host = host , port = port )
511
+ log_config = log_config or LOGGING_CONFIG # fall back to uvicorn default
512
+ uvicorn .run (web_app , host = host , port = port , log_config = log_config )
501
513
502
514
503
515
@serve_app .command ("demo" )
@@ -571,6 +583,9 @@ def serve_config(
571
583
"This verifies that the configuration is compatible with scaled (multi-process) deployments."
572
584
),
573
585
),
586
+ log_config : Optional [str ] = typer .Option (
587
+ None , help = "Custom uvicorn logging configuration file"
588
+ ),
574
589
):
575
590
"Serve a Tree as specified in configuration file(s)."
576
591
import os
@@ -605,9 +620,10 @@ def serve_config(
605
620
606
621
# Extract config for uvicorn.
607
622
uvicorn_kwargs = parsed_config .pop ("uvicorn" , {})
608
- # If --host is given, it overrides host in config. Same for --port.
623
+ # If --host is given, it overrides host in config. Same for --port and --log-config .
609
624
uvicorn_kwargs ["host" ] = host or uvicorn_kwargs .get ("host" , "127.0.0.1" )
610
625
uvicorn_kwargs ["port" ] = port or uvicorn_kwargs .get ("port" , 8000 )
626
+ uvicorn_kwargs ["log_config" ] = log_config or uvicorn_kwargs .get ("log_config" )
611
627
612
628
# This config was already validated when it was parsed. Do not re-validate.
613
629
logger .info (f"Using configuration from { Path (config_path ).absolute ()} " )
0 commit comments