Sort nginx access logs by numeric suffix
This commit is contained in:
parent
18beef724c
commit
24e2818d20
1 changed files with 8 additions and 7 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue