Hi,
How to append the log file name into the log line when sending to the grafana Loki using promtail? My log line does not include the name of the log file.
Thanks
Hi,
How to append the log file name into the log line when sending to the grafana Loki using promtail? My log line does not include the name of the log file.
Thanks
Hi @sachiru19911019,
I know it doesn’t answer your initial question but have you considered using Grafana Alloy instead? This automatically adds the filename as a label you can query by
local.file_match "applogs" {
path_targets = [{"__path__" = "/tmp/app-logs/app.log"}]
sync_period = "5s"
}
loki.write "local_loki" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
}
}
loki.source.file "local_files" {
targets = local.file_match.applogs.targets
forward_to = [loki.write.local_loki.receiver]
}
you can try an example in this online sandbox: Grafana Dev Testing | Killercoda
When you use promtail, the filename is a label.
Can you show as an unfolded expanded logline? Normaly there must be the filname.
Jo
Thank you for your response. Actually I can add filename as a label using promtail. In here, I need to see the file name within the log entry when I select just a job in Label filters. For an example,
This is my log line format.
01-06-2023 06:00:00.001 [Thread- 12] DEBUG ahjs sadfkjg - fgStats job ihgj
I want to see this as a out put on grafana loki.
01-06-2023 06:00:00.001 [Thread- 12] DEBUG ahjs sadfkjg - fgStats job ihgj log_file_name.log
Thanks
Hi @sachiru19911019, so you do have the “pack” pipeline stage which would convert your filename label and place it within a JSON structure of your logline: pack | Grafana Loki documentation
However, this would be removed as a log label. This sounds like a visualisation problem where it would make sense to see the label within the log line. within the log visualisation without needing to expand this log entry?:
OK thats what you want…
… |= `` | line_format {{ __line__ }} {{.filename}}
Did you find a solution?