V2: how do I get access logs?

1. My Caddy version (caddy -version):

(devel) (checked out yesterday, 2010-01-13)

2. How I run Caddy:

a. System environment:

OS, relevant versions, systemd? docker? etc.

Raspberry Pi

$ uname -a 
Linux gru 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux
Raspbian GNU/Linux 9

b. Command:

caddy run

d. My complete Caddyfile:

home.waynewerner.com {
    root * /var/www/waynewerner.com/site
}

3. The problem I’m having:

I can’t figure out how to get any kind of interesting logging. I’m also not actually getting it to return any kind of information, but mostly I’m interested in getting access logging. Nothing actually shows up in the logs when I connect to caddy so I can debug what’s going on here.

I’m pretty sure that it’s actually serving the request, though, because curl -v gives me this:

* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200 
< server: Caddy
< content-length: 0
< date: Tue, 14 Jan 2020 14:49:26 GMT
< 
* Curl_http_done: called premature == 0
* Connection #0 to host home.waynewerner.com left intact

And when I kill caddy I get a connection refused.

I’ve tried enabling access logging with:

curl localhost:2019/config/logging -X POST -H "Content-Type: application/json" -d '{"logs": {"access": {"level": "debug"}}}'

And

curl localhost:2019/config/logging -X POST -H "Content-Type: application/json" -d '{"logs": {"": {"level": "DEBUG"}}}'

But I haven’t found any example on https://github.com/caddyserver/caddy/wiki/v2:-Documentation#logging on how to actually get these logs.

4. Error messages and/or full log output:

2020/01/14 14:54:17.520	INFO	using adjacent Caddyfile
2020/01/14 14:54:17.525	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["localhost:2019"]}
2020/01/14 14:54:17.526	INFO	http	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "srv0", "https_port": 443}
2020/01/14 14:54:17.526	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "srv0"}
2020/01/14 14:54:17.527	INFO	http	enabling automatic TLS certificate management	{"domains": ["home.waynewerner.com"]}
2020/01/14 14:54:17 [INFO][cache:0x25a4040] Started certificate maintenance routine
2020/01/14 14:54:17.528	INFO	autosaved config	{"file": "/home/wayne/.config/caddy/autosave.json"}
2020/01/14 14:54:17.528	INFO	serving initial configuration

After doing curl localhost:2019/config/logging -X POST -H "Content-Type: application/json" -d '{"logs": {"access": {"level": "debug"}}}' I get this:

2020/01/14 14:54:17.528	INFO	serving initial configuration
2020/01/14 14:56:54.581	INFO	admin.api	received request	{"method": "POST", "uri": "/config/logging", "remote_addr": "127.0.0.1:60272", "headers": {"Accept":["*/*"],"Content-Length":["40"],"Content-Type":["application/json"],"User-Agent":["curl/7.52.1"]}}
2020/01/14 14:56:54.587	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["localhost:2019"]}
2020/01/14 14:56:54.588	INFO	http	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "srv0", "https_port": 443}
2020/01/14 14:56:54.588	INFO	http	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "srv0", "https_port": 443}
2020/01/14 14:56:54.588	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "srv0"}
2020/01/14 14:56:54.588	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "srv0"}
2020/01/14 14:56:54.589	INFO	http	enabling automatic TLS certificate management	{"domains": ["home.waynewerner.com"]}
2020/01/14 14:56:54.589	INFO	http	enabling automatic TLS certificate management	{"domains": ["home.waynewerner.com"]}
2020/01/14 14:56:54 [INFO][cache:0x24eca00] Started certificate maintenance routine
2020/01/14 14:56:54 http: Accept error: accept tcp 127.0.0.1:2019: i/o timeout; retrying in 5ms
2020/01/14 14:56:54.601	INFO	tls	cleaned up storage units
2020/01/14 14:56:54.601	INFO	tls	cleaned up storage units
2020/01/14 14:56:54 [INFO][cache:0x25a4040] Stopped certificate maintenance routine
2020/01/14 14:56:54.602	INFO	autosaved config	{"file": "/home/wayne/.config/caddy/autosave.json"}
2020/01/14 14:56:55.089	INFO	admin	stopped previous server

So… how do I get access to my logs to figure out what I’m doing wrong with my config settings?

Welcome @waynejwerner ! Thanks for trying Caddy 2 while it’s still in beta.

There’s not yet a way to enable them via the Caddyfile (that’s coming later this or next month) but all you have to do is set the “logs” field of the server: https://caddyserver.com/docs/json/apps/http/servers/logs/

For default access logs, just set it to an empty object ({}).

1 Like

Ah, got it:

curl localhost:2019/config/apps/http/servers/srv0/logs/ -X POST -H "Content-Type: application/json" -d '{}'

I had to include the srv0 in there.

Thanks!