mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-08-04 13:47:37 +02:00
Fix logging (#14122)
Fixes logging without introducing more junk into FrigateApp.
This commit is contained in:
parent
54900ae318
commit
e5e196bd7f
@ -6,7 +6,7 @@ import secrets
|
|||||||
import shutil
|
import shutil
|
||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
from multiprocessing.synchronize import Event as MpEvent
|
||||||
from typing import Any, Optional
|
from typing import Optional
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
import uvicorn
|
import uvicorn
|
||||||
@ -30,7 +30,6 @@ from frigate.comms.webpush import WebPushClient
|
|||||||
from frigate.comms.ws import WebSocketClient
|
from frigate.comms.ws import WebSocketClient
|
||||||
from frigate.comms.zmq_proxy import ZmqProxy
|
from frigate.comms.zmq_proxy import ZmqProxy
|
||||||
from frigate.config.config import FrigateConfig
|
from frigate.config.config import FrigateConfig
|
||||||
from frigate.config.logger import LogLevel
|
|
||||||
from frigate.const import (
|
from frigate.const import (
|
||||||
CACHE_DIR,
|
CACHE_DIR,
|
||||||
CLIPS_DIR,
|
CLIPS_DIR,
|
||||||
@ -78,10 +77,8 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class FrigateApp:
|
class FrigateApp:
|
||||||
audio_process: Optional[mp.Process] = None
|
def __init__(self, config: FrigateConfig) -> None:
|
||||||
|
self.audio_process: Optional[mp.Process] = None
|
||||||
# TODO: Fix FrigateConfig usage, so we can properly annotate it here without mypy erroring out.
|
|
||||||
def __init__(self, config: Any) -> None:
|
|
||||||
self.stop_event: MpEvent = mp.Event()
|
self.stop_event: MpEvent = mp.Event()
|
||||||
self.detection_queue: Queue = mp.Queue()
|
self.detection_queue: Queue = mp.Queue()
|
||||||
self.detectors: dict[str, ObjectDetectProcess] = {}
|
self.detectors: dict[str, ObjectDetectProcess] = {}
|
||||||
@ -92,7 +89,7 @@ class FrigateApp:
|
|||||||
self.ptz_metrics: dict[str, PTZMetrics] = {}
|
self.ptz_metrics: dict[str, PTZMetrics] = {}
|
||||||
self.processes: dict[str, int] = {}
|
self.processes: dict[str, int] = {}
|
||||||
self.region_grids: dict[str, list[list[dict[str, int]]]] = {}
|
self.region_grids: dict[str, list[list[dict[str, int]]]] = {}
|
||||||
self.config: FrigateConfig = config
|
self.config = config
|
||||||
|
|
||||||
def ensure_dirs(self) -> None:
|
def ensure_dirs(self) -> None:
|
||||||
for d in [
|
for d in [
|
||||||
@ -388,7 +385,7 @@ class FrigateApp:
|
|||||||
|
|
||||||
# create or update region grids for each camera
|
# create or update region grids for each camera
|
||||||
for camera in self.config.cameras.values():
|
for camera in self.config.cameras.values():
|
||||||
if camera.name:
|
assert camera.name is not None
|
||||||
self.region_grids[camera.name] = get_camera_regions_grid(
|
self.region_grids[camera.name] = get_camera_regions_grid(
|
||||||
camera.name,
|
camera.name,
|
||||||
camera.detect,
|
camera.detect,
|
||||||
@ -564,19 +561,6 @@ class FrigateApp:
|
|||||||
def start(self) -> None:
|
def start(self) -> None:
|
||||||
logger.info(f"Starting Frigate ({VERSION})")
|
logger.info(f"Starting Frigate ({VERSION})")
|
||||||
|
|
||||||
# setup logging
|
|
||||||
logging.getLogger().setLevel(self.config.logger.default.value.upper())
|
|
||||||
|
|
||||||
log_levels = {
|
|
||||||
"werkzeug": LogLevel.error,
|
|
||||||
"ws4py": LogLevel.error,
|
|
||||||
"httpx": LogLevel.error,
|
|
||||||
**self.config.logger.logs,
|
|
||||||
}
|
|
||||||
|
|
||||||
for log, level in log_levels.items():
|
|
||||||
logging.getLogger(log).setLevel(level.value.upper())
|
|
||||||
|
|
||||||
# Ensure global state.
|
# Ensure global state.
|
||||||
self.ensure_dirs()
|
self.ensure_dirs()
|
||||||
|
|
||||||
|
@ -289,7 +289,9 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
default_factory=dict, title="Frigate environment variables."
|
default_factory=dict, title="Frigate environment variables."
|
||||||
)
|
)
|
||||||
logger: LoggerConfig = Field(
|
logger: LoggerConfig = Field(
|
||||||
default_factory=LoggerConfig, title="Logging configuration."
|
default_factory=LoggerConfig,
|
||||||
|
title="Logging configuration.",
|
||||||
|
validate_default=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Global config
|
# Global config
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from pydantic import Field
|
from pydantic import Field, ValidationInfo, model_validator
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
from .base import FrigateBaseModel
|
from .base import FrigateBaseModel
|
||||||
|
|
||||||
@ -20,3 +22,17 @@ class LoggerConfig(FrigateBaseModel):
|
|||||||
logs: dict[str, LogLevel] = Field(
|
logs: dict[str, LogLevel] = Field(
|
||||||
default_factory=dict, title="Log level for specified processes."
|
default_factory=dict, title="Log level for specified processes."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@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())
|
||||||
|
Loading…
Reference in New Issue
Block a user