"""
Logging configuration for the MCP server
"""
import logging
import sys
import structlog
from typing import Any, Dict, Optional
def configure_logging(log_level: str = "INFO") -> None:
"""
Configure structured logging for the application
Args:
log_level: The log level to use (DEBUG, INFO, WARNING, ERROR, CRITICAL)
"""
# Set the log level
log_level_value = getattr(logging, log_level.upper())
# Configure structlog processors
processors = [
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.processors.JSONRenderer()
]
# Configure structlog
structlog.configure(
processors=processors,
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
# Configure standard logging
logging.basicConfig(
format="%(message)s",
stream=sys.stdout,
level=log_level_value,
)
# Set log level for third-party libraries
logging.getLogger("uvicorn").setLevel(logging.WARNING)
logging.getLogger("fastapi").setLevel(logging.WARNING)
# Get a logger
logger = structlog.get_logger("mcp_server")
logger.info("Logging configured", log_level=log_level)