""" Logging configuration for Tracker microservice. """ import logging import sys from typing import Optional try: from insightfy_utils.logging import get_logger as _insight_get_logger from insightfy_utils.logging import setup_logging as _insight_setup_logging except Exception: _insight_get_logger = None _insight_setup_logging = None def setup_logging( level: str = "INFO", format_type: str = "colored", app_name: Optional[str] = None, include_correlation: bool = True ) -> None: """ Configure logging for the application. Uses insightfy_utils logging when available, falls back to standard logging. """ if _insight_setup_logging: _insight_setup_logging( level=level, format_type=format_type, app_name=app_name or "tracker-microservice", include_correlation=include_correlation ) return # Fallback to standard logging log_level = getattr(logging, level.upper(), logging.INFO) logging.basicConfig( level=log_level, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler(sys.stdout)] ) # Set specific log levels for noisy libraries logging.getLogger("motor").setLevel(logging.WARNING) logging.getLogger("pymongo").setLevel(logging.WARNING) logging.getLogger("asyncpg").setLevel(logging.WARNING) logging.getLogger("httpx").setLevel(logging.WARNING) logging.getLogger("httpcore").setLevel(logging.WARNING) logging.getLogger("uvicorn.access").setLevel(logging.WARNING) def get_logger(name: str) -> logging.Logger: """Get a logger instance""" if _insight_get_logger: return _insight_get_logger(name) return logging.getLogger(name)