Loki Log Stream and Filter Expressions
Log Stream Selector
Loki log stream selectors define which log streams to include in your query. Here are some examples:
{job="varlogs"}
{job="varlogs", host="nginx01"}
{job=~"nginx*", host="nginx01"}
{job="varlogs", host="nginx01", filename="/var/log/syslog"}
Line Filter Expressions
Each line filter expression has a filter operator followed by text or a regular expression. These filter operators are supported:
| Operator | Description |
|---|---|
| ` | =` |
!= | Log line does not contain string |
| ` | ~` |
!~ | Log line does not contain a match to a regex |
Examples
-
Include log lines containing
"error":{job="varlogs", host="nginx01"} |= "error" -
Exclude log lines containing
"info":{job="varlogs", host="nginx01"} != "info" -
Include log lines matching
warnorerrorusing regex:{job=~"nginx*", host="nginx01"} |~ "warn|error" -
Advanced example with JSON parsing and custom line formatting:
{job=~"nginx*", host="nginx01"} |~ "warn|error" | json | line_format " {{.detected_level}} {{.remote_addr}} {{.status}}"