Merge pull request #4 from wagesj45/codex/sort-log-files-by-numeric-suffix

Update log rotation sort order
This commit is contained in:
Jordan Wages 2025-07-17 23:54:59 -05:00 committed by GitHub
commit 4a473682c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,13 +48,14 @@ if row and row[0]:
last_dt = None
try:
log_files = sorted(
[
os.path.join(LOG_DIR, f)
for f in os.listdir(LOG_DIR)
if LOG_FILE_PATTERN.match(f)
]
)
log_files = []
for f in os.listdir(LOG_DIR):
match = LOG_FILE_PATTERN.match(f)
if match:
suffix = match.group(1)
number = int(suffix.lstrip(".")) if suffix else 0
log_files.append((number, os.path.join(LOG_DIR, f)))
log_files = [path for _, path in sorted(log_files, key=lambda x: x[0], reverse=True)]
except FileNotFoundError:
print(f"[ERROR] Log directory not found: {LOG_DIR}")
exit(1)