Search an app's or container's logs for a pattern and return matches WITH surrounding
context — useful for finding where something went wrong (errors, tracebacks, a request
ID, etc.). Logs are fetched once and grepped locally, so unlike the `search` argument
on the log tools you get the lines around each hit, not just the matching line.
Args:
identifier: App name/ID (e.g. "my-app", "ap-123456") or container ID ("ta-123456").
pattern: Text (or regex, if `regex=True`) to search for, e.g. "Traceback", "Error",
"timeout", or a request/job ID.
target: What `identifier` refers to: "app" (default) or "container".
regex: If True, treat `pattern` as a Python regular expression instead of literal text.
case_sensitive: If True, match case-sensitively. Defaults to case-insensitive.
context_lines: Number of lines to include before and after each match. Defaults to 3.
max_matches: Cap on the number of match blocks returned. Defaults to 50.
since: Only search logs newer than this — ISO 8601 or relative like "2h", "1d".
tail: Only search the last N log entries. If neither `since` nor `tail` is given,
the last 1000 entries are searched.
timeout_seconds: Max seconds to spend fetching logs before searching. Defaults to 30.
env: Optional Modal environment (apps only).
Returns:
A dictionary with `match_count` (total hits), `matches` (a list of context blocks,
each a string with line numbers; matched lines are prefixed with ">"), and
`returned` (how many blocks are included after `max_matches`).