"""SSO MCP Checklist Server.
MCP server providing software development checklists with Azure Entra ID SSO authentication.
"""
from __future__ import annotations
import logging
import sys
import structlog
__version__ = "0.1.0"
__all__ = ["__version__", "configure_logging", "get_logger"]
def configure_logging(log_level: str = "INFO") -> None:
"""Configure structured logging for the application.
Sets up structlog with appropriate processors for both development
and production use. In development (TTY), uses colored console output.
In production, uses JSON formatting.
Args:
log_level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL).
"""
# Convert string level to logging constant
level = getattr(logging, log_level.upper(), logging.INFO)
# Determine if we're in a TTY (development) or not (production)
is_tty = sys.stderr.isatty()
# Shared processors for all outputs
shared_processors: list[structlog.types.Processor] = [
structlog.contextvars.merge_contextvars,
structlog.processors.add_log_level,
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
]
if is_tty:
# Development: colored console output
processors: list[structlog.types.Processor] = [
*shared_processors,
structlog.dev.ConsoleRenderer(colors=True),
]
else:
# Production: JSON output
processors = [
*shared_processors,
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
]
structlog.configure(
processors=processors,
wrapper_class=structlog.make_filtering_bound_logger(level),
context_class=dict,
logger_factory=structlog.PrintLoggerFactory(),
cache_logger_on_first_use=True,
)
# Also configure standard library logging to use structlog
logging.basicConfig(
format="%(message)s",
level=level,
handlers=[logging.StreamHandler()],
)
def get_logger(name: str | None = None) -> structlog.stdlib.BoundLogger:
"""Get a structured logger instance.
Args:
name: Optional logger name for context.
Returns:
Configured structlog logger instance.
"""
logger = structlog.get_logger()
if name:
logger = logger.bind(logger_name=name)
return logger