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
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue