fix(logging): suppress uvicorn access logs and prevent duplicate logging
All checks were successful
Build and Push Docker Image / build (push) Successful in 14s
All checks were successful
Build and Push Docker Image / build (push) Successful in 14s
This commit is contained in:
@@ -26,6 +26,7 @@ def setup_logging() -> None:
|
|||||||
|
|
||||||
logger = logging.getLogger("grist_mcp")
|
logger = logging.getLogger("grist_mcp")
|
||||||
logger.setLevel(level)
|
logger.setLevel(level)
|
||||||
|
logger.propagate = False # Prevent duplicate logs to root logger
|
||||||
|
|
||||||
# Only add handler if not already configured
|
# Only add handler if not already configured
|
||||||
if not logger.handlers:
|
if not logger.handlers:
|
||||||
|
|||||||
@@ -191,14 +191,16 @@ def _print_mcp_config(external_port: int, tokens: list) -> None:
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
class HealthCheckFilter(logging.Filter):
|
class UvicornAccessFilter(logging.Filter):
|
||||||
"""Suppress health check requests unless LOG_LEVEL is DEBUG."""
|
"""Suppress uvicorn access logs unless LOG_LEVEL is DEBUG.
|
||||||
|
|
||||||
|
At INFO level, only grist_mcp tool logs are shown.
|
||||||
|
At DEBUG level, all HTTP requests are visible.
|
||||||
|
"""
|
||||||
|
|
||||||
def filter(self, record: logging.LogRecord) -> bool:
|
def filter(self, record: logging.LogRecord) -> bool:
|
||||||
if "/health" in record.getMessage():
|
# Only show uvicorn access logs at DEBUG level
|
||||||
# Only show health checks at DEBUG level
|
return os.environ.get("LOG_LEVEL", "INFO").upper() == "DEBUG"
|
||||||
return os.environ.get("LOG_LEVEL", "INFO").upper() == "DEBUG"
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -209,8 +211,8 @@ def main():
|
|||||||
|
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
|
||||||
# Add health check filter to uvicorn access logger
|
# Suppress uvicorn access logs at INFO level (only show tool logs)
|
||||||
logging.getLogger("uvicorn.access").addFilter(HealthCheckFilter())
|
logging.getLogger("uvicorn.access").addFilter(UvicornAccessFilter())
|
||||||
|
|
||||||
if not _ensure_config(config_path):
|
if not _ensure_config(config_path):
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user