ovdashboard/api/ovdashboard_api/__init__.py

49 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 .app import app
from .settings import SETTINGS
__all__ = ["app"]
class LogConfig(BaseModel):
"""
Logging configuration to be set for the server.
https://stackoverflow.com/a/67937084
"""
# Logging config
version = 1
disable_existing_loggers = False
formatters = {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(levelprefix)s [%(asctime)s] %(name)s: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
}
handlers = {
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
}
loggers = {
"ovdashboard_api": {
"handlers": ["default"],
"level": SETTINGS.log_level,
},
}
dictConfig(LogConfig().dict())