Sort nginx access logs by numeric suffix

This commit is contained in:
Jordan Wages 2025-07-17 23:54:23 -05:00
commit 24e2818d20

View file

@ -48,13 +48,14 @@ if row and row[0]:
last_dt = None last_dt = None
try: try:
log_files = sorted( log_files = []
[ for f in os.listdir(LOG_DIR):
os.path.join(LOG_DIR, f) match = LOG_FILE_PATTERN.match(f)
for f in os.listdir(LOG_DIR) if match:
if LOG_FILE_PATTERN.match(f) 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: except FileNotFoundError:
print(f"[ERROR] Log directory not found: {LOG_DIR}") print(f"[ERROR] Log directory not found: {LOG_DIR}")
exit(1) exit(1)