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
|
|
|
|
2022-09-05 13:11:57 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2022-09-07 00:17:25 +00:00
|
|
|
from .settings import SETTINGS
|
|
|
|
|
2022-09-05 13:11:57 +00:00
|
|
|
|
|
|
|
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 = {
|
2022-09-05 13:11:57 +00:00
|
|
|
"default": {
|
|
|
|
"()": "uvicorn.logging.DefaultFormatter",
|
2022-09-07 00:17:25 +00:00
|
|
|
"fmt": "%(levelprefix)s [%(asctime)s] %(name)s: %(message)s",
|
2022-09-05 13:11:57 +00:00
|
|
|
"datefmt": "%Y-%m-%d %H:%M:%S",
|
|
|
|
},
|
|
|
|
}
|
2023-10-16 18:06:55 +00:00
|
|
|
handlers: dict = {
|
2022-09-05 13:11:57 +00:00
|
|
|
"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-05 13:11:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-04 23:25:40 +00:00
|
|
|
|
2023-10-17 12:45:56 +00:00
|
|
|
dictConfig(LogConfig().model_dump())
|