'How to add the level tag in Promtail config
I’m using grafana loki to compose dashboards.
I need to group the logs by level to create the graph but in the details of the logs I can not see the level label:

my logs are like this:
2021-05-31 14:23:00.005 INFO 1 --- [ scheduling-1] AssociationService : Scheduler Association finish at 31-05-2021 02:23:00
There is a way to extrapolate the level and associate it to the label "level"?
Solution 1:[1]
you might want to use the regex stage:
- job_name: my-job
pipeline_stages:
- regex:
# extracts only log_level from the log line
expression: '\s+(?P<log_level>\D+)\s.*'
- labels:
# sources extracted log_level as label 'level' value
level: log_level
the expression above matches only log_level, but you may add more named capture groups and use them in the same way
i.e.
^(?P<time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3})\s+(?P<log_level>\S+)\s(?P<rest>.*)$
or less strict:
(?P<time>\S+\s\S+)\s+(?P<log_level>\D+)\s(?P<rest>.*)
match time, log_level and the rest of the line an extract them for later use.
check regex101 playground
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ??????? ????? |
