Console Time Stamping

1. Caddy version (caddy version):

root@caddy:~ # caddy version
v2.4.0-beta.2 h1:DUaK4qtL3T0/gAm0fVVkHgcMN04r4zGpfPUZWHRR8QU=

2. How I run Caddy:

I use Caddyfile rather than JSON.

a. System environment:

TrueNAS 12.0-U3 (a FreeBSD derivative)

b. Command:

service caddy start

c. Service/unit/compose file:


d. My complete Caddyfile or JSON config:

This snippet is relevant:

(logging) {
  log {
    format json {
      time_format iso8601
    output file /var/log/caddy/{args.0}.log {
      roll_size 100MiB    # Default 100MiB
      roll_keep 10        # Default 10
      roll_keep_for 90d   # Default 90d

A typical application of this snippet: {
  import logging

3. The problem I’m having:

Access logs become much more human-readable and useful because of the ISO8601 time format e.g.

{"level":"info","ts":"2021-05-02T12:37:27.793+0800","logger":"http.log.access.log0","msg":"handled request","request":{"remote_addr":"","proto":"HTTP/1.1","method":"HEAD","host":"","uri":"/","headers":{"X-Forwarded-For":[""],"Cf-Ray":["648e8de8fa395523-EWR"],"X-Forwarded-Proto":["https"],"Cf-Visitor":["{\"scheme\":\"https\"}"],"Cf-Request-Id":["09ccf7059c0000552354286000000001"],"Connection":["Keep-Alive"],"Accept-Encoding":["gzip"],"Cf-Ipcountry":["US"],"User-Agent":["jetmon/1.0 (Jetpack Site Uptime Monitor by"],"Cf-Connecting-Ip":[""],"Cdn-Loop":["cloudflare"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"","proto_mutual":true,"server_name":""}},"common_log":" - - [02/May/2021:12:37:27 +0800] \"HEAD / HTTP/1.1\" 200 0","duration":0.467530061,"size":0,"status":200,"resp_headers":{"Server":["Caddy","Caddy"],"Link":["<>; rel=\"\"","<>; rel=\"alternate\"; type=\"application/json\"","<>;rel=shortlink"],"Vary":["Accept-Encoding, Cookie"],"X-Powered-By":["PHP/7.4.16"],"Date":["Sun, 02 May 2021 04:37:27 GMT"],"Content-Type":["text/html; charset=UTF-8"]}}

However, this is a site option and not a global option and seems to apply to access logs only.

Is it possible to have similar time stamping for console output as well? It appears though that this is more like a global option. I have noticed there is a format console option, but again, this appears to be a site rather than a global option.

Here’s sample console log entry:

{"level":"info","ts":1619862602.6494813,"logger":"tls","msg":"cleaned up storage units"}
{"level":"info","ts":1619862602.6599119,"msg":"autosaved config (load with --resume flag)","file":"/.config/caddy/autosave.json"}
{"level":"info","ts":1619862602.6599343,"msg":"serving initial configuration"}

4. Error messages and/or full log output:


5. What I already tried:

Studied the various links in the next section.

6. Links to relevant resources:

  1. Global options
  2. log - Access logging
  3. Time_format examples please

Yeah - so as of v2.4.0-beta.2, it’s possible to configure logging via global options in general. The docs haven’t been pushed yet for that because we only push docs along with stable releases (to try and avoid confusion, because it’s a bit complicated to embed version information for changes to the docs, it makes it kinda wordy in some situations cause it’s written in regular English), but here it is:


I’ve tried it. It works really well. This is what the updated global section in my Caddyfile looks like now:

  acme_dns cloudflare [REDACTED]
#  debug
  log {
    format json {
      time_format iso8601

…and here’s some sample output from the console. Nice!..

{"level":"info","ts":"2021-05-02T23:12:07.123+0800","logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0xc000170850"}
{"level":"info","ts":"2021-05-02T23:12:07.124+0800","msg":"autosaved config (load with --resume flag)","file":"/.config/caddy/autosave.json"}
{"level":"info","ts":"2021-05-02T23:12:07.124+0800","logger":"admin.api","msg":"load complete"}

I still use the snippet though for access logging. Am I correct in saying that the log directive will (with Caddy v2.4.0-beta 2 and later) work with both global and site Caddy blocks?

The log directive will continue to only configure access logs, and the global option lets you configure all types of logs (by default skipping access logs if you configured access logs for other sites)

Directives are specifically things that appear inside of site blocks.


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