mirror of
https://github.com/Sun-ZhenXing/mcp-template-python.git
synced 2026-02-04 10:13:31 +00:00
feat: update log format
This commit is contained in:
@@ -2,6 +2,8 @@ import sys
|
||||
|
||||
import click
|
||||
|
||||
from mcp_template_python.utils.log import UVICORN_LOGGING_CONFIG
|
||||
|
||||
from .__about__ import __module_name__, __version__
|
||||
from .app import MCP_MAP
|
||||
from .config import settings
|
||||
@@ -25,6 +27,7 @@ def run_server(
|
||||
host=host,
|
||||
port=port,
|
||||
reload=reload,
|
||||
log_config=UVICORN_LOGGING_CONFIG,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
0
src/mcp_template_python/utils/__init__.py
Normal file
0
src/mcp_template_python/utils/__init__.py
Normal file
44
src/mcp_template_python/utils/log.py
Normal file
44
src/mcp_template_python/utils/log.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from typing import Any
|
||||
|
||||
from rich.console import Console
|
||||
from rich.logging import RichHandler
|
||||
|
||||
|
||||
class UvicornRichHandler(RichHandler):
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
super().__init__(
|
||||
console=Console(stderr=True), rich_tracebacks=True, *args, **kwargs
|
||||
)
|
||||
|
||||
|
||||
UVICORN_LOGGING_CONFIG = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"default": {
|
||||
"()": "uvicorn.logging.DefaultFormatter",
|
||||
"fmt": "%(message)s",
|
||||
"use_colors": False,
|
||||
},
|
||||
"access": {
|
||||
"()": "uvicorn.logging.AccessFormatter",
|
||||
"fmt": '%(client_addr)s - "%(request_line)s" %(status_code)s', # noqa: E501
|
||||
"use_colors": False,
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"default": {
|
||||
"formatter": "default",
|
||||
"class": "mcp_template_python.utils.log.UvicornRichHandler",
|
||||
},
|
||||
"access": {
|
||||
"formatter": "access",
|
||||
"class": "mcp_template_python.utils.log.UvicornRichHandler",
|
||||
},
|
||||
},
|
||||
"loggers": {
|
||||
"uvicorn": {"handlers": ["default"], "level": "INFO", "propagate": False},
|
||||
"uvicorn.error": {"level": "INFO"},
|
||||
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user