From f6eba9c39628058145bf76fcbf1a284c62bfded2 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 12 Aug 2025 14:25:11 +0000 Subject: [PATCH] log-search: Add --extra filter, for [dm] and similar filters. --- scripts/log-search | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/log-search b/scripts/log-search index d1aa51966d..2cf2641242 100755 --- a/scripts/log-search +++ b/scripts/log-search @@ -111,6 +111,11 @@ def parser() -> argparse.ArgumentParser: "-C", help="Only include requests whose client/user-agent contains this string", ) + filtering.add_argument( + "--extra", + "-X", + help="Only include requests whose logline includes this in [extra] flags", + ) output = parser.add_argument_group("Output") output.add_argument("--full-line", "-F", help="Show full matching line", action="store_true") @@ -167,9 +172,9 @@ PYTHON_LOG_LINE_RE = re.compile( (?P [A-Z]+ ) \s+ (?P \d+ ) \s+ (?P \S+ ) \s+ # This can be "217ms" or "1.7s" - ( \( [^)]+ \) \s+ )* + ( \( (?P [^)]+ ) \) \s+ )* (?P (?P /\S* ) ) \s+ - .* # Multiple extra things can go here + (?P .* ) # Multiple extra things can go here \( (?P ( (?P \d+ ) | unauth ) @@ -414,6 +419,12 @@ def parse_filters( filter_funcs.append(lambda m, t=args.client: t in m["user_agent"]) filter_terms.append(args.client) + if args.extra: + if args.nginx: + raise parser().error("nginx logs do not contain [extra] data; try without --nginx") + filter_funcs.append(lambda m, t=args.extra: t in m["extra"]) + filter_terms.append(args.extra) + return (filter_types, filter_funcs, filter_terms)