
- Update database path configuration for better compatibility - Add comprehensive logging system with error handling - Create supervisord.conf with proper configuration - Add environment variable example file - Enhance health check endpoint to report database status - Add detailed startup and shutdown event handlers - Update documentation with troubleshooting information - Update requirements with additional helpful packages
39 lines
1003 B
Python
39 lines
1003 B
Python
import logging
|
|
import sys
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class LogConfig(BaseModel):
|
|
"""Logging configuration to be set for the server"""
|
|
|
|
LOGGER_NAME: str = "blogging_api"
|
|
LOG_FORMAT: str = "%(levelprefix)s | %(asctime)s | %(message)s"
|
|
LOG_LEVEL: str = "INFO"
|
|
|
|
# Logging config
|
|
version: int = 1
|
|
disable_existing_loggers: bool = False
|
|
formatters: dict = {
|
|
"default": {
|
|
"()": "uvicorn.logging.DefaultFormatter",
|
|
"fmt": LOG_FORMAT,
|
|
"datefmt": "%Y-%m-%d %H:%M:%S",
|
|
},
|
|
}
|
|
handlers: dict = {
|
|
"default": {
|
|
"formatter": "default",
|
|
"class": "logging.StreamHandler",
|
|
"stream": sys.stderr,
|
|
},
|
|
}
|
|
loggers: dict = {
|
|
LOGGER_NAME: {"handlers": ["default"], "level": LOG_LEVEL},
|
|
}
|
|
|
|
|
|
def get_logger(name: str = None) -> logging.Logger:
|
|
"""Get logger with the given name"""
|
|
name = name or LogConfig().LOGGER_NAME
|
|
return logging.getLogger(name) |