From 4701bedde4f2eb3f0cae18b71caf6915f8a321b4 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 24 Jun 2025 16:13:25 -0600 Subject: [PATCH] Use other logging redirect class --- frigate/data_processing/common/face/model.py | 2 +- frigate/detectors/plugins/cpu_tfl.py | 2 +- frigate/embeddings/onnx/face_embedding.py | 2 +- frigate/events/audio.py | 5 ++++- frigate/log.py | 4 ++-- frigate/util/classification.py | 4 +++- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/frigate/data_processing/common/face/model.py b/frigate/data_processing/common/face/model.py index 7736298bb..b04f4f6ae 100644 --- a/frigate/data_processing/common/face/model.py +++ b/frigate/data_processing/common/face/model.py @@ -38,7 +38,7 @@ class FaceRecognizer(ABC): def classify(self, face_image: np.ndarray) -> tuple[str, float] | None: pass - @redirect_stdout_to_logger(__name__, logging.DEBUG) + @redirect_stdout_to_logger(logger, logging.DEBUG) def init_landmark_detector(self) -> None: landmark_model = os.path.join(MODEL_CACHE_DIR, "facedet/landmarkdet.yaml") diff --git a/frigate/detectors/plugins/cpu_tfl.py b/frigate/detectors/plugins/cpu_tfl.py index 128ce45a5..d884a1c7e 100644 --- a/frigate/detectors/plugins/cpu_tfl.py +++ b/frigate/detectors/plugins/cpu_tfl.py @@ -28,7 +28,7 @@ class CpuDetectorConfig(BaseDetectorConfig): class CpuTfl(DetectionApi): type_key = DETECTOR_KEY - @redirect_stdout_to_logger(__name__, logging.DEBUG) + @redirect_stdout_to_logger(logger, logging.DEBUG) def __init__(self, detector_config: CpuDetectorConfig): interpreter = Interpreter( model_path=detector_config.model.path, diff --git a/frigate/embeddings/onnx/face_embedding.py b/frigate/embeddings/onnx/face_embedding.py index d9b62451f..7f507783d 100644 --- a/frigate/embeddings/onnx/face_embedding.py +++ b/frigate/embeddings/onnx/face_embedding.py @@ -54,7 +54,7 @@ class FaceNetEmbedding(BaseEmbedding): self._load_model_and_utils() logger.debug(f"models are already downloaded for {self.model_name}") - @redirect_stdout_to_logger(__name__, logging.DEBUG) + @redirect_stdout_to_logger(logger, logging.DEBUG) def _load_model_and_utils(self): if self.runner is None: if self.downloader: diff --git a/frigate/events/audio.py b/frigate/events/audio.py index acdbbbd09..bb4a60ae1 100644 --- a/frigate/events/audio.py +++ b/frigate/events/audio.py @@ -49,6 +49,9 @@ except ModuleNotFoundError: from tensorflow.lite.python.interpreter import Interpreter +logger = logging.getLogger(__name__) + + def get_ffmpeg_command(ffmpeg: FfmpegConfig) -> list[str]: ffmpeg_input: CameraInput = [i for i in ffmpeg.inputs if "audio" in i.roles][0] input_args = get_ffmpeg_arg_list(ffmpeg.global_args) + ( @@ -423,7 +426,7 @@ class AudioEventMaintainer(threading.Thread): class AudioTfl: - @redirect_stdout_to_logger(__name__, logging.DEBUG) + @redirect_stdout_to_logger(logger, logging.DEBUG) def __init__(self, stop_event: threading.Event, num_threads=2): self.stop_event = stop_event self.num_threads = num_threads diff --git a/frigate/log.py b/frigate/log.py index d479c7f93..ab0bfeda9 100644 --- a/frigate/log.py +++ b/frigate/log.py @@ -189,11 +189,11 @@ class LogRedirect(io.StringIO): self.flush() -def redirect_stdout_to_logger(log_name: str, level: int) -> Any: +def redirect_stdout_to_logger(logger: logging.Logger, level: int) -> Any: def decorator(func: Callable): @wraps(func) def wrapper(*args, **kwargs): - current_log_pipe = LogRedirect(log_name, logging.ERROR) + current_log_pipe = LogRedirect(logger, logging.ERROR) old_stdout = sys.stdout old_stderr = sys.stderr diff --git a/frigate/util/classification.py b/frigate/util/classification.py index b7339aec3..e3a75ad15 100644 --- a/frigate/util/classification.py +++ b/frigate/util/classification.py @@ -17,6 +17,8 @@ BATCH_SIZE = 16 EPOCHS = 50 LEARNING_RATE = 0.001 +logger = logging.getLogger(__name__) + def __generate_representative_dataset_factory(dataset_dir: str): def generate_representative_dataset(): @@ -37,7 +39,7 @@ def __generate_representative_dataset_factory(dataset_dir: str): return generate_representative_dataset -@redirect_stdout_to_logger(__name__, logging.DEBUG) +@redirect_stdout_to_logger(logger, logging.DEBUG) def __train_classification_model(model_name: str) -> bool: """Train a classification model."""