mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-08-02 17:12:16 +03:00
Ensure logging config is propagated to forked processes (#18704)
* Move log level initialization to log * Use logger config * Formatting * Fix config order * Set process names --------- Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>
This commit is contained in:
committed by
Blake Blackshear
co-authored by
Nicolas Mowen
parent
a6b80c0f9c
commit
4deccf08a1
@@ -5,6 +5,7 @@ import os
|
||||
import sys
|
||||
import threading
|
||||
from collections import deque
|
||||
from enum import Enum
|
||||
from logging.handlers import QueueHandler, QueueListener
|
||||
from multiprocessing.managers import SyncManager
|
||||
from queue import Queue
|
||||
@@ -33,6 +34,15 @@ LOG_HANDLER.addFilter(
|
||||
not in record.getMessage()
|
||||
)
|
||||
|
||||
|
||||
class LogLevel(str, Enum):
|
||||
debug = "debug"
|
||||
info = "info"
|
||||
warning = "warning"
|
||||
error = "error"
|
||||
critical = "critical"
|
||||
|
||||
|
||||
log_listener: Optional[QueueListener] = None
|
||||
log_queue: Optional[Queue] = None
|
||||
|
||||
@@ -61,6 +71,22 @@ def _stop_logging() -> None:
|
||||
log_listener = None
|
||||
|
||||
|
||||
def apply_log_levels(default: str, log_levels: dict[str, LogLevel]) -> None:
|
||||
logging.getLogger().setLevel(default)
|
||||
|
||||
log_levels = {
|
||||
"absl": LogLevel.error,
|
||||
"httpx": LogLevel.error,
|
||||
"tensorflow": LogLevel.error,
|
||||
"werkzeug": LogLevel.error,
|
||||
"ws4py": LogLevel.error,
|
||||
**log_levels,
|
||||
}
|
||||
|
||||
for log, level in log_levels.items():
|
||||
logging.getLogger(log).setLevel(level.value.upper())
|
||||
|
||||
|
||||
# When a multiprocessing.Process exits, python tries to flush stdout and stderr. However, if the
|
||||
# process is created after a thread (for example a logging thread) is created and the process fork
|
||||
# happens while an internal lock is held, the stdout/err flush can cause a deadlock.
|
||||
|
||||
Reference in New Issue
Block a user