Is it possible to capture a string with a space in it? I am parsing the log for labels, because it is crooked in the source without labels. I use pattern. Cannot capture date and time in one tag
Example Log
INFO: GeoBlock: 2023/06/04 08:25:30 geoblock@file: request denied [183.136.225.45] for country [CN]
Query
sum by (message, country, date, time, ip) (rate({container_name="traefik"} | logfmt | __error__=`` | pattern `<_>: <_>: <date> <time> <_>: <message> [<ip>] <_> [<country>]` [$__range]))
You can use pattern and then combine datestamp and timestamp with line_format. I have an example on your other posts that you can reference to.
However, I would say that in general you should not have to or want to parse log lines for time stamps. You should be doing that during log ingestion, so that the logs are stored on Loki with the correct time stamp matching that of the log lines.
2023/06/04-08:25:30 geoblock@file: request denied [183.136.225.45] for country [CN] INFO: GeoBlock: 2023/06/04 08:25:30 geoblock@file: request denied [183.136.225.45] for country [CN]
Again, this is not how you should do it. See my other reply below.
That’s what I was referring to in my original post. You should parse your logline and change the timestamp to that instead of using local time of your log agent. I don’t know what log agent you use, but a generic flow should be something like this:
Given log line:
INFO: GeoBlock: 2023/06/04 08:25:30 geoblock@file: request denied [183.136.225.45] for country [CN]
Parse it (however your log agent does it) and get the date and time (2023/06/04 08:25:30).
Set the log line timestamp to 2023/06/04 08:25:30.