refactor: migrate all remaining modules to use shared aitbc.logging from aitbc-core package
- Replace `import logging` with `from aitbc.logging import get_logger` across blockchain-node scripts and coordinator-api modules - Update logger initialization from `logging.getLogger(__name__)` to `get_logger(__name__)` in 30+ files - Add production configuration validators for API keys, HMAC secret, and JWT secret in coordinator config - Enhance coordinator startup with comprehensive initialization logging
This commit is contained in:
@@ -48,10 +48,40 @@ from contextlib import asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Lifecycle events for the Coordinator API."""
|
||||
logger.info("Starting Coordinator API")
|
||||
# Initialize database if needed
|
||||
init_db()
|
||||
|
||||
try:
|
||||
# Initialize database
|
||||
init_db()
|
||||
logger.info("Database initialized successfully")
|
||||
|
||||
# Validate configuration
|
||||
if settings.app_env == "production":
|
||||
logger.info("Production environment detected, validating configuration")
|
||||
# Configuration validation happens automatically via Pydantic validators
|
||||
|
||||
# Initialize audit logging directory
|
||||
from pathlib import Path
|
||||
audit_dir = Path(settings.audit_log_dir)
|
||||
audit_dir.mkdir(parents=True, exist_ok=True)
|
||||
logger.info(f"Audit logging directory: {audit_dir}")
|
||||
|
||||
# Log service startup details
|
||||
logger.info(f"Coordinator API started on {settings.app_host}:{settings.app_port}")
|
||||
logger.info(f"Database adapter: {settings.database.adapter}")
|
||||
logger.info(f"Environment: {settings.app_env}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to start Coordinator API: {e}")
|
||||
raise
|
||||
|
||||
yield
|
||||
|
||||
logger.info("Shutting down Coordinator API")
|
||||
try:
|
||||
# Cleanup resources
|
||||
logger.info("Coordinator API shutdown complete")
|
||||
except Exception as e:
|
||||
logger.error(f"Error during shutdown: {e}")
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
# Initialize rate limiter
|
||||
|
||||
Reference in New Issue
Block a user