Prompt
stack traces split across multiple log lines
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
When a stack trace is split across multiple log lines, the key is to detect the start of an error/exception and then join the following indented lines until the trace ends.
A few common approaches:
1) Ingest as multiline logs
If you control log collection, configure the log shipper/parser to treat stack traces as one event.
Examples
- Fluent Bit / Fluentd: multiline parser
- Filebeat:
multiline.pattern - Logstash: multiline codec/filter
- Vector / Promtail / CloudWatch agent: multiline support
Typical rule:
- Start a new event when a line begins with a timestamp or log level
- Append lines that start with whitespace or
at ...to the previous event
2) Regex-based grouping
A common heuristic for Java/Python/.NET stack traces:
- New record: line starts with date/time, log level, or exception header
- Continuation: line starts with whitespace,
at,Caused by:,... n more, etc.
Example pattern ideas:
- Start line:
^\d{4}-\d{2}-\d{2}or^(INFO|WARN|ERROR|DEBUG) - Continuation line:
^\s+at\s+|^\s+Caused by:|^\s*\.\.\. \d+ more
3) If parsing in code
You can reconstruct events by buffering lines:
events = []
buffer = []
def is_start(line):
return line[:4].isdigit() or line.startswith(("INFO", "WARN", "ERROR", "DEBUG"))
for line in lines:
if is_start(line) and buffer:
events.append("\n".join(buffer))
buffer = [line]
else:
buffer.append(line)
if buffer:
events.append("\n".join(buffer))
4) Best practices
- Prefer single-line JSON logs for machine parsing
- If stack traces are required, ensure your logging framework emits them as a single field
- Use consistent prefixes/timestamps so multiline grouping is reliable
If you want, I can help with a specific tool (Filebeat, Logstash, Fluent Bit, Splunk, CloudWatch, etc.) and give you the exact multiline config.