| """ | |
| Logging utilities for Notification Microservice - Phase 5 | |
| """ | |
| import structlog | |
| import logging | |
| import sys | |
| def configure_logging(): | |
| """Configure structured JSON logging for the notification service""" | |
| structlog.configure( | |
| processors=[ | |
| structlog.stdlib.add_log_level, | |
| structlog.stdlib.add_logger_name, | |
| structlog.processors.TimeStamper(fmt="iso"), | |
| structlog.processors.StackInfoRenderer(), | |
| structlog.processors.format_exc_info, | |
| structlog.processors.UnicodeDecoder(), | |
| structlog.processors.JSONRenderer() | |
| ], | |
| 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=logging.INFO, | |
| ) | |
| def get_logger(name: str): | |
| """Get a structured logger instance""" | |
| return structlog.get_logger(name) | |
| # Auto-configure on import | |
| configure_logging() | |