ovdashboard/api/ovdashboard_api/__init__.py

46 lines
1 KiB
Python

"""
Package `ovdashboard_api`: Contains the API powering the
"OVDashboard" application.
This file: Sets up logging.
"""
from logging.config import dictConfig
from pydantic import BaseModel
from .settings import SETTINGS
class LogConfig(BaseModel):
"""
Logging configuration to be set for the server.
https://stackoverflow.com/a/67937084
"""
# Logging config
version: int = 1
disable_existing_loggers: bool = False
formatters: dict = {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(levelprefix)s [%(asctime)s] %(name)s: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
}
handlers: dict = {
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
}
loggers: dict = {
"ovdashboard_api": {
"handlers": ["default"],
"level": SETTINGS.log_level,
},
}
dictConfig(LogConfig().model_dump())