Basic label selector
A LogQL query starts with a label matcher in braces to select a stream of logs. For example, to select logs from the stream where the labelapp equals api:
app="api".
Label selectors are the cheapest and most selective filters you can apply. Always start by narrowing streams with label matchers before adding pipeline filters.
Filtering by text (contains)
After selecting a stream, use pipeline operators to filter the content of log lines. Use|= to include only lines that contain a substring. Example: show only log lines that contain the word DELETE:
Filtering by route or other substrings
You can filter any substring in the line. For example, to find requests to the/users route:
Negation (exclude matches)
To exclude lines that contain a substring use the not-equals pipeline operator!=:
!~:
Regular expression matching
To filter lines that match a regex, use the match operator|~. For example, to keep only GET or POST entries:
GET or POST):
Quick reference: common pipeline operators
Parsing JSON log lines and filtering extracted fields
When your logs are structured JSON, parse them with the| json pipeline stage. This extracts top-level JSON fields and makes them available for direct comparisons.
For example, to find entries whose parsed code field equals 500 while excluding GET/POST methods:
| json):
Avoid parsing every log line with
| json if you only need a subset — parse after applying text/regex filters to reduce processing. Also be cautious with broad regexes; they can be expensive and slow queries.Putting it all together
The general pattern is:- Use label matchers to narrow to the relevant stream(s).
- Apply pipeline operators (
|=,!=,|~,!~) to include/exclude by text or regex. - Use
| jsonto parse structured logs, then filter on extracted fields.