It doesn’t start, complaining about “log” being unrecognized directive
4. Error messages and/or full log output:
Jan 25 22:09:02 proxy caddy[15444]: 2020/01/25 22:09:02.575 INFO using provided configuration {"config_file": "/etc/caddy/Caddyfile", "config_adapter": ""}
Jan 25 22:09:02 proxy caddy[15444]: run: adapting config using caddyfile: /etc/caddy/Caddyfile:7: unrecognized directive: log
Jan 25 22:09:02 proxy caddy[15440]: start: caddy process exited with error: exit status 1
5. What I already tried:
it works properly after removing the “log” and “errors” lines. But I would like to have logs
I tried to move the “log” and “errors” into the global section and also into the domain section (out of the “reverse_proxy” context), neither of them helped.
Is this expected to work? Did logging changed (and docs/examples not updated?)
Caddy v1 and Caddy v2 configurations are not compatible, there have been many significant changes to the internal functionality of the server that required breaking changes.
Unfortunately, because it’s still in beta, Caddyfile directives for logging haven’t been implemented yet. It will probably be added in the next few releases.
For now, I if you need logs, you’ll need to use JSON config (you can dump your existing config with the caddy adapt command as a starting point). All you have to do is set the “logs” field of the server: JSON Config Structure - Caddy Documentation. For default access logs, just set it to an empty object ( {} ).
Any update on how I can enable logging and write to a specific file as of 2.0 beta 13? The updated documentation doesn’t show much as it relates to logging.
Thanks Mohammed90. I’ve got it working with the example you posted above. Does this logging key also enable me to get access logs or do I need to use the “logs” key under apps/http/servers? In Caddy 1 I was able to achieve this by simply using the “log” directive.
To write only access logs, you’d set an include rule for only http.log.access. See logs/include on JSON Config Structure - Caddy Documentation and the description of logs/exclude which mentions http.log.access.
Documentation will definitely be improved in this area over time.