Fix frigate log deduplication (#16759)

This commit is contained in:
Josh Hawkins 2025-02-23 07:25:50 -06:00 committed by GitHub
parent 71f1ea86d2
commit 22cbf74dc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -659,25 +659,42 @@ def process_logs(
if " " not in clean_line: if " " not in clean_line:
clean_line = f"{datetime.now()} {clean_line}" clean_line = f"{datetime.now()} {clean_line}"
# Find the position of the first double space to extract timestamp and message try:
date_end = clean_line.index(" ") # Find the position of the first double space to extract timestamp and message
timestamp = clean_line[:date_end] date_end = clean_line.index(" ")
message_part = clean_line[date_end:].strip() timestamp = clean_line[:date_end]
full_message = clean_line[date_end:].strip()
if message_part == last_message: # For frigate, remove the date part from message comparison
repeat_count += 1 if service == "frigate":
continue # Skip the date at the start of the message if it exists
else: date_parts = full_message.split("]", 1)
if repeat_count > 0: if len(date_parts) > 1:
# Insert a deduplication message formatted the same way as logs message_part = date_parts[1].strip()
dedup_message = f"{last_timestamp} [LOGGING] Last message repeated {repeat_count} times" else:
log_lines.append(dedup_message) message_part = full_message
repeat_count = 0 else:
message_part = full_message
if message_part == last_message:
repeat_count += 1
continue
else:
if repeat_count > 0:
# Insert a deduplication message formatted the same way as logs
dedup_message = f"{last_timestamp} [LOGGING] Last message repeated {repeat_count} times"
log_lines.append(dedup_message)
repeat_count = 0
log_lines.append(clean_line)
last_timestamp = timestamp
last_message = message_part
except ValueError:
# If we can't parse the line properly, just add it as is
log_lines.append(clean_line) log_lines.append(clean_line)
last_timestamp = timestamp continue
last_message = message_part
# If there were repeated messages at the end, log the count # If there were repeated messages at the end, log the count
if repeat_count > 0: if repeat_count > 0: