Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
log-search: Auto-limit to the correct logfile when searching datetimes.
Alex Vandiver175e61486e0a
diff --git a/scripts/log-search b/scripts/log-searchindex f7f65a49a9f..fd63f6e716d 100755--- a/scripts/log-search+++ b/scripts/log-search@@ -8,7 +8,7 @@ import osimport reimport signalimport sys-from datetime import datetime, timedelta+from datetime import date, datetime, timedelta, timezonefrom enum import Enum, autofrom typing import List, Match, Optional, Set, TextIO, Tuple@@ -248,6 +248,28 @@ def parse_logfile_names(args: argparse.Namespace) -> List[str]:else: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]if args.all_logs:logfile_count = 15