Spaces:
Paused
Paused
feat(query-timing): implement comprehensive query timing and performance monitoring across the application
833f3b2 | import logging | |
| import sys | |
| LOG_FORMAT = "%(asctime)s %(levelname)s %(name)s %(message)s" | |
| def setup_logging(level: str = "INFO"): | |
| """Configure application logging with query timing support. | |
| Args: | |
| level: Base logging level (INFO, DEBUG, WARNING, etc.) | |
| The query timing logger can be independently controlled via: | |
| - INFO: Shows medium and slow queries (>500ms) | |
| - DEBUG: Shows all queries with timing | |
| - WARNING: Shows only slow queries (>1s) | |
| """ | |
| logging.basicConfig( | |
| level=level, | |
| format=LOG_FORMAT, | |
| stream=sys.stdout | |
| ) | |
| logging.getLogger("uvicorn.access").setLevel(logging.WARNING) | |
| # Configure query timing logger | |
| # Set to INFO to see medium/slow queries, DEBUG to see all queries | |
| query_logger = logging.getLogger("sqlalchemy.query.timing") | |
| query_logger.setLevel(logging.INFO) # Change to DEBUG to see all query timings | |
| # Suppress SQLAlchemy's default echo to avoid duplicate logs | |
| logging.getLogger("sqlalchemy.engine").setLevel(logging.WARNING) | |