Log parsing is the process of turning raw, often unstructured log lines into structured records with named fields. A parser recognizes the format of a line, for example JSON, key=value pairs or a fixed text pattern, and extracts values such as timestamp, severity, message and context attributes. Parsing can happen when logs are collected, in a telemetry pipeline before storage, or at query time, and it is the basis for filtering, aggregating and alerting on log data.
What is log parsing?
Many applications, proxies and operating system components still write logs as plain text. A typical NGINX access log line looks like this:
203.0.113.7 - - [05/Nov/2026:09:14:03 +0000] "GET /api/cart HTTP/1.1" 502 157 "-" "Mozilla/5.0"
For a human the meaning is clear, for a query engine it is just a string. Log parsing extracts the parts into fields such as client.address, http.request.method, url.path, http.response.status_code and a proper timestamp. Only then can you count 502 responses per path, build dashboards or alert on error rates. Applications that already emit structured logs need far less parsing, but third party components rarely give you that choice.
Common parsing methods
- JSON parsing: the simplest and most robust case. Each line is a JSON object, and fields are taken over directly.
- Key value parsing: lines like
level=error user=42 duration_ms=870are split on delimiters. - Regular expressions: named capture groups extract fields from fixed text formats. Flexible, but they can become hard to maintain and are relatively expensive at high volume.
- Grok patterns: a library of named, reusable regex building blocks known from Logstash, for example
%{IPORHOST:client} %{WORD:method}. - Dissect or delimiter parsing: splits a line by fixed separators without regex, which is faster for strictly positional formats.
As an illustration, a regex for the beginning of the access log line above could be:
^(?P<client>\S+) \S+ \S+ \[(?P<time>[^\]]+)\] "(?P<method>\S+) (?P<path>\S+)[^"]*" (?P<status>\d{3})
Timestamps, severity and multiline logs
Three details decide whether parsed logs are trustworthy:
- Timestamps: the event time should be taken from the line itself, with the correct format and time zone. Otherwise the ingestion time is used, and events appear out of order.
- Severity: text values such as
WARN,warningor numeric syslog levels should be mapped to a consistent log level, in OpenTelemetry toSeverityTextandSeverityNumber. - Multiline entries: a Java stack trace spans many lines that belong to one event. A multiline rule, typically a pattern that recognizes the start of a new entry, joins them before parsing.
Where parsing happens
There are three places to parse logs, each with trade-offs:
- At collection: agents such as the OpenTelemetry Collector with its
filelogreceiver use operators likejson_parser,regex_parserorkey_value_parserand can parse container runtime formats directly. - In a pipeline before storage: a central telemetry pipeline parses, enriches and filters logs from many sources consistently. This is also the right place for PII masking, because extracted fields can be masked precisely.
- At query time: schema-on-read systems store the raw line and extract fields when a query runs. This keeps you flexible for formats you did not anticipate, but costs compute on every query.
In practice teams combine them: well known formats are parsed early, rare or new ones at query time.
Pitfalls and best practices
- Keep the raw line or at least the original message when parsing fails, so no information is lost. Count parse failures as a metric.
- Expect format changes: a new log field or a library upgrade can break a regex silently. Test parsers against sample lines in CI.
- Prefer cheap parsers: JSON, key value and dissect are faster than complex regexes. Anchor regexes and avoid catastrophic backtracking.
- Use consistent field names, ideally OpenTelemetry semantic conventions, so parsed logs line up with traces and metrics.
- Fix the source when possible: switching your own services to structured logging removes the need for fragile parsers.
Our article on structured logging best practices covers the source side, and reducing log costs shows how parsed fields help to filter and aggregate noise.
How Obseria helps
Obseria collects logs via OpenTelemetry, the Obseria Agent or existing shippers. The Obseria Pipeline parses, filters and masks personal data before storage, and log analytics stores logs in Obseria Lake with schema-on-read, so unstructured lines can still be parsed at query time when needed. Parsed fields are available for dashboards and alerts, logs carrying trace IDs are linked to their traces, and Obseria Intelligence can help draft parsing rules for unfamiliar log formats.