Questions about logs

1. Caddy version (caddy version):

2.46

2. How I run Caddy:

a. System environment:

Win10 v21H2 x64

b. Command:

caddy run

c. Service/unit/compose file:

d. My complete Caddyfile or JSON config:

{
	log caddy-log {
		output file caddy.log
	}
	default_sni myweb.com
}
web.myweb.com:8443 {
	reverse_proxy :81
	tls {
		protocols tls1.3
	}
	log {
		output file web_access.log {
			roll true # Rotate logs, enabled by default
			roll_size_mb 5 # Set max size 5 MB
			roll_local_time true # Use localhost time
			roll_keep 2 # Keep at most 2 log files
		}
		level ERROR
	}
	header / Strict-Transport-Security "max-age=63072000"
}

3. The problem I’m having:

  1. Is there a way to have the log record system timestamp? I found param “roll_local_time” somewhere but it is not in the documentation.

  2. I can’t get the domain log to ever create, never get the web_access.log file.

  3. Is it possible to make the output more human readable? It looks like minified JSON with super long lines.

  4. Is it possible to not output to the console?

4. Error messages and/or full log output:

5. What I already tried:

I’ve been thru the documentation, forum, and the web, but could not discern answers to these questions.

6. Links to relevant resources:

Ah, the Caddyfile adapter doesn’t support that option yet. it’s JSON only currently. Oops. I can fix that.

So, to clarify, roll_local_time is “Whether to use local timestamps in rolled filenames.”

Is that what you’re looking for, or are you looking for the timestamps in the individual logs messages themselves to be localized?

If you want to change the time format, you can use the time_format on the encoder options. But right now there’s no way to set those to local time, they default to UTC. In general UTC is the best default because it’s immune to timezone issues like daylight savings time etc.

Are you sure your user as which you’re running Caddy has permissions to write to that location?

You can use the console encoder which is somewhat nicer. But yeah, Caddy’s logs are structured logs.

You can use the discard writer. Make sure to configure the default logger in global options (see the docs).

FYI this line will only match requests to exactly the path / and nothing else. Remove the / to make it apply to all requests.

You won’t really gain anything by turning off TLS 1.2. I strongly recommend just leaving the defaults here.

1 Like

Right, I want the timestamp in the log to be local. UTC doesn’t benefit my operations.

Yep, it is the same location that caddy.log is written.

Oh my gosh - I added format console and now the timestamp in the file is “1.645289661425477e+09”!

If I do this I won’t even get log file output (all output is discarded), right?

Thanks for the other tips.

Use time_format to fix that.

For now, you’ll need to use some external tooling to transform the timestamps. There’s currently no way to emit local time in logs.

You can set up more than one logger. Make the default one discard, then configure another to log to file.

But really, you should probably run Caddy in such a way that stdout/stderr are captured and written to file. You can do this by running Caddy as a windows service. See the docs for instructions for that:

To fix the timestamp, I tried:

format console {
			time_format MMM dd yy HH:mm:ss
		}

but Caddy didn’t like that, so I tried:

format console {
			time_format "MMM dd yy HH:mm:ss"
		}

but then the timestamp is that exact string!
The docs don’t show to use this parameter.

Any idea how to get the site log to produce?

You can use any of the time formats in the code here:

Or follow the formatting defined by the Go time package:

You’re right that this should be better documented.

1 Like

Thank you.

This topic was automatically closed after 30 days. New replies are no longer allowed.