ovdashboard/api/ovdashboard_api/__init__.py

47 lines
1 KiB
Python
Raw Normal View History

2022-09-05 12:54:02 +00:00
"""
2022-09-05 12:58:00 +00:00
Package `ovdashboard_api`: Contains the API powering the
2022-09-05 12:54:02 +00:00
"OVDashboard" application.
This file: Sets up logging.
"""
2022-09-07 00:29:32 +00:00
from logging.config import dictConfig
2022-09-04 23:25:40 +00:00
from pydantic import BaseModel
2022-09-07 00:17:25 +00:00
from .settings import SETTINGS
class LogConfig(BaseModel):
"""
Logging configuration to be set for the server.
https://stackoverflow.com/a/67937084
"""
# Logging config
2023-10-16 18:06:55 +00:00
version: int = 1
disable_existing_loggers: bool = False
formatters: dict = {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
2022-09-07 00:17:25 +00:00
"fmt": "%(levelprefix)s [%(asctime)s] %(name)s: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
}
2023-10-16 18:06:55 +00:00
handlers: dict = {
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
}
2023-10-16 18:06:55 +00:00
loggers: dict = {
2022-09-07 00:17:25 +00:00
"ovdashboard_api": {
"handlers": ["default"],
"level": SETTINGS.log_level,
},
}
2022-09-04 23:25:40 +00:00
2023-10-17 12:45:56 +00:00
dictConfig(LogConfig().model_dump())