Closed valankar closed 6 months ago
The logger being configured in your example is the logger for Caddy itself. By default that logger doesn't do access logging, only logs for things like issuing TLS certificates, debug logging if you set debug
in your global block, etc.
But I'm pretty sure if you do something like the following I think you will indeed get what you're after.
https://mysite.com {
log {
output loki ... {
label {
site {host}
}
}
}
}
Please give that a go and let me know!
Thanks. I realized using {host}
is not such a good idea because it's in the HTTP request and can be filled with garbage.
Instead I did something like this:
(loki-site-log) {
log {
output loki ... {
label {
job caddy
site {args[0]}
}
}
}
}
www.mysite.com {
import loki-site-log www.mysite.com
}
This seems to work. However, I have a bunch of sites. I'm thinking this creates a logging network connection for each one. Not sure if that is creating new ones unnecessarily.
While it's true that {host}
would be from the host header, if the site is www.mysite.com
like that, Caddy will have already matched it so you could be sure it was the expected value.
I'm thinking this creates a logging network connection for each one. Not sure if that is creating new ones unnecessarily.
The method that this module and the underlying loki-sink-for-zap module uses is just to push the logs over HTTP to Loki's ingress. So I personally wouldn't be too worried about it.
Ok, thanks.
I would like to set a label based on the site/host. I tried:
But seems that doesn't work. I suppose because global doesn't have an idea of
{host}
.Is there perhaps a right way to do this? Can I override or add labels in each site config outside of global?