Hi, i have a problem with my stage.timestamp in grafana alloy, here is my configuration:
local.file_match "tomcat_logs" {
path_targets = [{
__address__ = "ibiatap01",
__path__ = "/opt/tomcat_a/logs/webapps_blue/analytics/main.log",
app = "analytics",
environment = "blue",
job = "tomcat",
},
{
__address__ = "ibiatap01",
__path__ = "/opt/tomcat_a/logs/webapps_green/analytics/main.log",
app = "analytics",
environment = "green",
job = "tomcat",
}]
}
loki.process "tomcat_logs" {
stage.regex {
expression = "\\[(?P<tenant>[^\\]]*)\\]\\*? (?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}); (?P<thread>[^;]+); \\[(?P<level>[^\\]]+)\\]; (?P<component>[^;]+); (?P<message>.+)"
}
stage.multiline {
firstline = "\\[(?P<tenant>[^\\]]*)\\]\\*? (?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}); (?P<thread>[^;]+); \\[(?P<level>[^\\]]+)\\]; (?P<component>[^;]+); (?P<message>.+)"
}
stage.labels {
values = {
tenant = "tenant",
thread = "thread",
level = "level",
component = "component",
time = "time",
}
}
stage.timestamp {
source = "time"
format = "2006-01-02 15:04:05,999"
}
forward_to = [loki.write.default.receiver]
}
loki.source.file "tomcat_logs" {
targets = local.file_match.tomcat_logs.targets
forward_to = [loki.process.tomcat_logs.receiver]
}
loki.write "default" {
endpoint {
url = "http://10.221.9.61:3100/loki/api/v1/push"
}
external_labels = {}
}
livedebugging {
enabled = true
}
Everything works correctly if i don’t add the stage.timestamp setted. when i set it, is like alloy is not able to detect the format of the rows of the log. I’m sure that the regex is correct because i checked with regex101: build, test, and debug regex and i douboled all the \ like wrote in the documentation of alloy. My logs file have this kink of formati, i show following some lines:
[tenant.test]* 2025-03-18 08:44:49,192; ajp-nio-0.0.0.0-8010-exec-2; [ERROR]; HeadTag; com.agency.IA.dispatchers.actiondescriptor.internal.IASessionExpiredException: IASessionExpiredException - Instance not found, need redirect to login page
And there are also line that should be catched as multiline that are like the log line before but after that a stack trace that don’t match the regex.
I really need and help to undestrand what is the problem of the stage.timestamp because my goal is to map the time extracted from the log line to the time of the log line in grafana e loki