I’d like to have log files for each subdomain that is proxied. I haven’t figured out how to do this. I want the Caddy log file for the Caddy-only stuff, then subdomain logs for the subdomain-specific stuff.
I’ve tried using a logging function that creates a log file based on a passed in filename, and I tried a log statement in the server block, but neither creates any specific log file.
You didn’t specify a path to the file, so Caddy would try to write it to the current working directory. Where that is depends on how you started Caddy.
Maybe I should ask this way - is logging per subdomain (server) possible? Caddy doesn’t complain about the config file. Is my config valid? All I know is it doesn’t produce anything new or different than w/o the server block directives.
The Caddy process probably doesn’t have permission to write to that location. I can’t really help with that part, permissions on Windows is not something I have much experience with.
Write permissions is not the problem. (If Caddy couldn’t write, I’d hope it would show some kind of error.)
I had to escape the backslash because Caddy would error if I didn’t. Even Caddy knows to do it: redirected default logger {"from": "stderr", "to": "D:\\BIN\\caddy\\caddy.log"}
Then it sounds like something is broken, at least on Windows. Or maybe my expectations are incorrect. What would be logged in the per server log file?
I run Caddy with .\caddy.exe run --config Caddyfile, then make a request with curl -v http://localhost:8881. It creates a log file foo.log in the PWD (the dir I ran the command), and it has the access log written to it.
I also tried with import logging E:\foo to write the log file to a separate disk, and that worked too.
I also added log caddy-log like you had in your original post and it also wrote a caddy.log file, with foo.log still containing access logs.
I can’t replicate that. I use output file E:\test\foo.log and it writes there without issue as well.
FWIW, I’m on Windows 11, you said you’re on Windows 10. No idea if that makes a difference (I should hope not) but yeah
I was using an actual app, like File Browser or Emby, to generate traffic. I’m also using an RP, which you did not use. Do you get a log with a RP?
It looks like it might be because of an external connection. I used this:
(logging) {
log {
output file "{args.0}.log"
}
}
some.external.com:8443 {
respond "I am 8081"
import logging foo
}
:8081 {
respond "I am 8081"
import logging foo
}
curl -v http://localhost:8081 returns "I am 8081" and creates foo.log. curl -v https://some.external.com:443 returns "I am 8081" but does not create foo.log. (executed from another network, not looped)
local curl did produce foo-int.log
external curl did not produce foo-ext.log
A would also say that Caddy is a bit overzealous with this warning in the Caddy log 2X every second! This quickly grows the log file. WARN caddyfile Placeholder {args.0} deprecated, use {args[0]} instead
“every second”? It should only log that when you adapt your config, i.e. when Caddy starts. I guess you must be using --watch? It tries to adapt and reload the config constantly.
Ooooh I have a hunch now.
I think the problem has to do with the fact that your site address is some.external.com:8443 with a port number. If you adapt your config with caddy adapt -c Caddyfile -p you’ll see logger_names which includes the port number.
I think this is bug, because I think we try to match logger names by the hostname only and not the port, so we don’t find a matching logger name for that request and the access log never gets written.
I’ll play around with this a bit more but I think if you use the https_port 8443 global option for now and omit the port from site addresses, it might work as a workaround until I fix that bug.