Get original entry value in LogQL line_format
Asked Answered
L

3

7

In LogQL line_format template expression, is there a way to access the original log entry (assume the entry is not in JSON or any parseable format and all labels are log labels and not extracted labels).

example: ... | line_format "{{.log_label1}}, {{.log_label2}}: {{<some way to show the entire original log entry>}}"

Lille answered 24/3, 2021 at 15:31 Comment(0)
B
7

One way it to prepend it with a regular expression capturing the entire message

... |regexp '(?P<message>.*)' |line_format "{{.some_other_var}} {{.message}}"

Note that the ' around the regex should really by ` otherwise it might not work

Besse answered 25/3, 2021 at 16:57 Comment(2)
The regexp is a nice trick, thanks! I wonder if there is some "default" variable that would allow the same without involving another parser...Lille
Yup, I was wondering that too and then found your question :) sadly the documentation is not really that good , though it is a great productBesse
E
8

You can use the line template function:

... | line_format "{{.host}} {{ __line__ }}"
Editorial answered 31/5, 2023 at 11:20 Comment(0)
B
7

One way it to prepend it with a regular expression capturing the entire message

... |regexp '(?P<message>.*)' |line_format "{{.some_other_var}} {{.message}}"

Note that the ' around the regex should really by ` otherwise it might not work

Besse answered 25/3, 2021 at 16:57 Comment(2)
The regexp is a nice trick, thanks! I wonder if there is some "default" variable that would allow the same without involving another parser...Lille
Yup, I was wondering that too and then found your question :) sadly the documentation is not really that good , though it is a great productBesse
B
0

It looks like instead of regexp you can use json parser:

... | json | line_format "{{.stream}}: {{.log}}"
Batho answered 12/7, 2022 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.