2024-10-03 14:33:53 +02:00
|
|
|
import logging
|
2024-09-28 21:21:42 +02:00
|
|
|
from enum import Enum
|
|
|
|
|
2024-10-03 14:33:53 +02:00
|
|
|
from pydantic import Field, ValidationInfo, model_validator
|
|
|
|
from typing_extensions import Self
|
2024-09-28 21:21:42 +02:00
|
|
|
|
|
|
|
from .base import FrigateBaseModel
|
|
|
|
|
|
|
|
__all__ = ["LoggerConfig", "LogLevel"]
|
|
|
|
|
|
|
|
|
|
|
|
class LogLevel(str, Enum):
|
|
|
|
debug = "debug"
|
|
|
|
info = "info"
|
|
|
|
warning = "warning"
|
|
|
|
error = "error"
|
|
|
|
critical = "critical"
|
|
|
|
|
|
|
|
|
|
|
|
class LoggerConfig(FrigateBaseModel):
|
|
|
|
default: LogLevel = Field(default=LogLevel.info, title="Default logging level.")
|
|
|
|
logs: dict[str, LogLevel] = Field(
|
|
|
|
default_factory=dict, title="Log level for specified processes."
|
|
|
|
)
|
2024-10-03 14:33:53 +02:00
|
|
|
|
|
|
|
@model_validator(mode="after")
|
|
|
|
def post_validation(self, info: ValidationInfo) -> Self:
|
|
|
|
if isinstance(info.context, dict) and info.context.get("install", False):
|
|
|
|
logging.getLogger().setLevel(self.default.value.upper())
|
|
|
|
|
|
|
|
log_levels = {
|
|
|
|
"werkzeug": LogLevel.error,
|
|
|
|
"ws4py": LogLevel.error,
|
|
|
|
**self.logs,
|
|
|
|
}
|
|
|
|
|
|
|
|
for log, level in log_levels.items():
|
|
|
|
logging.getLogger(log).setLevel(level.value.upper())
|