Usage of sys.env in local.file_match in path

Hey,

I am having Problems figuring out how to use a windows Environment Variable created by an Applikation in the Path. I want to use it as Part of the Path because the app name can be different. This is the iteration where the app at least starts but doesn’t find anything.

appPath = C:\Program Files\app

local.file_match “app” {
path_targets = [
{path = “sys.env(appPath)\logs\*.log”},
** {path = “sys.env(appPath)\lib\version*.txt”},**
** {path = “sys.env(appPath)\webserver\standalone\log\*.log”},**
]
}

loki.source.file “app” {
targets = local.file_match.app.targets
forward_to = [loki.write.app.receiver]
}

loki.write “app” {
endpoint {
url = “https://loki.url
}
}

PS:

If you label here you get the same log for every file can you get different Labels for each discovered file?

local.file_match “app” {
path_targets = [
{path = “sys.env(appPath)\logs\.log", app = “log”},
{path = "sys.env(appPath)\lib\version
.txt”},
{path = “sys.env(appPath)\webserver\standalone\log\*.log”},
]
}

Try this:

local.file_match “app” {
  path_targets = [
    {"__path__" = string.format("%s\logs\*.log", sys.env("appPath"))}
  ]
}
1 Like

Hey Tony,

thanks that worked. Do you also know if you can label per file here?
Everything i tried removed the filename label and just replaced it with the label i set as above.

I want something like:

Machine(server1/2/3) → app(1/2/3) → log

or is it better to just use a labeling stage from loki.process or loki.relabel ?

You can keep the filename label (which should be provided for you with the local files block), and hardcode machine name and/or app name using env variable or automated configuration management.

1 Like