diff --git a/frigate/log.py b/frigate/log.py index d514fb0bd..ea075ba67 100644 --- a/frigate/log.py +++ b/frigate/log.py @@ -7,6 +7,7 @@ import queue import multiprocessing as mp from logging import handlers from setproctitle import setproctitle +from collections import deque def listener_configurer(): @@ -54,6 +55,7 @@ class LogPipe(threading.Thread): self.daemon = False self.logger = logging.getLogger(log_name) self.level = level + self.deque = deque(maxlen=100) self.fdRead, self.fdWrite = os.pipe() self.pipeReader = os.fdopen(self.fdRead) self.start() @@ -67,9 +69,13 @@ class LogPipe(threading.Thread): """Run the thread, logging everything. """ for line in iter(self.pipeReader.readline, ''): - self.logger.log(self.level, line.strip('\n')) + self.deque.append(line.strip('\n')) self.pipeReader.close() + + def dump(self): + while len(self.deque) > 0: + self.logger.log(self.level, self.deque.popleft()) def close(self): """Close the write end of the pipe. diff --git a/frigate/video.py b/frigate/video.py index e3625b00d..e68a5f49e 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -181,6 +181,7 @@ class CameraWatchdog(threading.Thread): now = datetime.datetime.now().timestamp() if not self.capture_thread.is_alive(): + self.logpipe.dump() self.start_ffmpeg_detect() elif now - self.capture_thread.current_frame.value > 20: self.logger.info(f"No frames received from {self.camera_name} in 20 seconds. Exiting ffmpeg...") @@ -197,6 +198,7 @@ class CameraWatchdog(threading.Thread): poll = p['process'].poll() if poll == None: continue + p['logpipe'].dump() p['process'] = start_or_restart_ffmpeg(p['cmd'], self.logger, p['logpipe'], ffmpeg_process=p['process']) # wait a bit before checking again