55import re
66import sys
77
8-
98import infinity_emb
109from infinity_emb ._optional_imports import CHECK_TYPER , CHECK_UVICORN
1110from infinity_emb .args import EngineArgs
@@ -107,6 +106,7 @@ def _construct(name: str):
107106
108107 tp = typer .Typer ()
109108
109+
110110 @tp .command ("v1" )
111111 def v1 (
112112 # v1 is deprecated. Please do no longer modify it.
@@ -177,6 +177,7 @@ def v1(
177177 proxy_root_path = "" , # set as empty string
178178 )
179179
180+
180181 @tp .command ("v2" )
181182 def v2 (
182183 # t
@@ -380,6 +381,8 @@ def v2(
380381 api_key = api_key ,
381382 proxy_root_path = proxy_root_path ,
382383 )
384+ # Update logging configs
385+ set_uvicorn_logging_configs ()
383386
384387 uvicorn .run (
385388 app ,
@@ -391,6 +394,47 @@ def v2(
391394 )
392395
393396
397+ def set_uvicorn_logging_configs ():
398+ """Configure Uvicorn logging with environment variable overrides.
399+
400+ Allows customization of log formats through environment variables:
401+ - INFINITY_UVICORN_DEFAULT_FORMAT: Format for default logs
402+ - INFINITY_UVICORN_ACCESS_FORMAT: Format for access logs
403+ - INFINITY_UVICORN_DATE_FORMAT: Date format for all logs
404+ """
405+ from uvicorn .config import LOGGING_CONFIG
406+ import os
407+
408+ # Define constants for environment variable names to improve maintainability
409+ default_format_env = MANAGER .uvicorn_default_format
410+ access_format_env = MANAGER .uvicorn_access_format
411+ date_format_env = MANAGER .uvicorn_date_format
412+
413+ # Default log format (can be overridden by env var)
414+ default_fmt = os .getenv (
415+ default_format_env ,
416+ "%(asctime)s %(levelprefix)s %(message)s"
417+ )
418+
419+ # Access log format (can be overridden by env var)
420+ access_fmt = os .getenv (
421+ access_format_env ,
422+ '%(asctime)s %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s'
423+ )
424+
425+ # Date format for all logs (can be overridden by env var)
426+ date_fmt = os .getenv (
427+ date_format_env ,
428+ "%Y-%m-%d %H:%M:%S"
429+ )
430+
431+ # Apply the configurations
432+ LOGGING_CONFIG ["formatters" ]["default" ]["fmt" ] = default_fmt
433+ LOGGING_CONFIG ["formatters" ]["default" ]["datefmt" ] = date_fmt
434+ LOGGING_CONFIG ["formatters" ]["access" ]["fmt" ] = access_fmt
435+ LOGGING_CONFIG ["formatters" ]["access" ]["datefmt" ] = date_fmt
436+
437+
394438def cli ():
395439 CHECK_TYPER .mark_required ()
396440 if len (sys .argv ) == 1 or sys .argv [1 ] not in [
0 commit comments