Search an app's or container's logs and return each hit WITH surrounding context —
the fastest way to find a traceback, an error or a request ID. Logs are fetched once
and grepped locally, so you get the lines around each match, not just the match.
Covers the stdout/stderr/system streams ONLY. Crash events shown on the Modal
dashboard (e.g. "... exited with ...") are not log lines, so a search for them
returns 0 matches even though the failure is real — check the dashboard instead.
Args:
identifier: App name/ID ("my-app", "ap-...") or container ID ("ta-...").
pattern: Text to find, or a Python regex when regex=True.
target: "auto" (default — "ta-..." is a container), "app", or "container".
regex / case_sensitive: Match mode. Both default False.
context_lines: Lines of context each side of a match. Default 3.
max_matches: Cap on match blocks returned. Default 50.
since / until: Time range, ISO 8601 or relative ("2h", "30m", "1d"). PREFER a
bounded range (both ends) when you know roughly when something happened —
`since` alone fetches every entry from then until now, which on a busy app
is megabytes and gets cut off at the timeout. Range must be <= 35 days.
tail: Search only the last N entries (max 20000) instead of a whole range.
With no since/until/tail, defaults to the last 1000 entries.
source: Search only "stdout", "stderr", or "system".
exclude: Drop lines matching this BEFORE searching, to strip repeated noise.
prefilter: Push `pattern` down to Modal as a server-side substring filter, so
non-matching lines are never fetched. The big lever for huge logs, but it
requires regex=False and leaves `context_lines` showing only other matching
lines — use it to find *where* something is, then re-query that window.
timestamps: Prefix lines with their timestamp. Default True.
timeout_seconds: Max seconds spent fetching logs. Default 30.
env: Modal environment (apps only).
Returns: {match_count (exact, whole log searched), returned (matches actually shown),
returned_blocks, matches (context blocks, matched lines prefixed ">"), excluded_lines,
output_capped}.