mirror of https://github.com/zulip/zulip.git
log-search: Auto-limit to the correct logfile when searching datetimes.
This commit is contained in:
parent
9eaaacba52
commit
175e61486e
|
@ -8,7 +8,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime, timedelta
|
from datetime import date, datetime, timedelta, timezone
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from typing import List, Match, Optional, Set, TextIO, Tuple
|
from typing import List, Match, Optional, Set, TextIO, Tuple
|
||||||
|
|
||||||
|
@ -248,6 +248,28 @@ def parse_logfile_names(args: argparse.Namespace) -> List[str]:
|
||||||
else:
|
else:
|
||||||
base_path = "/var/log/zulip/server.log"
|
base_path = "/var/log/zulip/server.log"
|
||||||
|
|
||||||
|
for term in args.filter_terms:
|
||||||
|
date_term = re.match(r"2\d\d\d-\d\d-\d\d", term)
|
||||||
|
if not date_term:
|
||||||
|
continue
|
||||||
|
# They're limiting to a specific day; find the right logfile
|
||||||
|
# which is going to have any matches
|
||||||
|
rotations = int(
|
||||||
|
(datetime.now(tz=timezone.utc).date() - date.fromisoformat(date_term[0]))
|
||||||
|
/ timedelta(days=1)
|
||||||
|
)
|
||||||
|
access_log_retention_days = int(
|
||||||
|
get_config(get_config_file(), "application_server", "access_log_retention_days", "14")
|
||||||
|
)
|
||||||
|
if rotations > access_log_retention_days:
|
||||||
|
raise RuntimeError(f"Date is too old (more than {access_log_retention_days} days ago)")
|
||||||
|
if rotations == 0:
|
||||||
|
return [base_path]
|
||||||
|
if rotations == 1:
|
||||||
|
return [f"{base_path}.1"]
|
||||||
|
else:
|
||||||
|
return [f"{base_path}.{rotations}.gz"]
|
||||||
|
|
||||||
logfile_names = [base_path]
|
logfile_names = [base_path]
|
||||||
if args.all_logs:
|
if args.all_logs:
|
||||||
logfile_count = 15
|
logfile_count = 15
|
||||||
|
|
Loading…
Reference in New Issue