caddyserver/caddy · error

setting up custom log '%s': %v

Error message

setting up custom log '%s': %v

What it means

After the sink and default logs, Caddy provisions each named custom log in logging.logs. This error wraps a provisioning failure for the named log — writer module errors, encoder problems, or invalid log level/filter configs — and includes the log's name.

Source

Thrown at logging.go:117

			return fmt.Errorf("setting up sink log: %v", err)
		}
	}

	// as a special case, set up the default structured Caddy log next
	if err := logging.setupNewDefault(ctx); err != nil {
		return err
	}

	// then set up any other custom logs
	for name, l := range logging.Logs {
		// the default log is already set up
		if name == DefaultLoggerName {
			continue
		}

		err := l.provision(ctx, logging)
		if err != nil {
			return fmt.Errorf("setting up custom log '%s': %v", name, err)
		}

		// Any other logs that use the discard writer can be deleted
		// entirely. This avoids encoding and processing of each
		// log entry that would just be thrown away anyway. Notably,
		// we do not reach this point for the default log, which MUST
		// exist, otherwise core log emissions would panic because
		// they use the Log() function directly which expects a non-nil
		// logger. Even if we keep logs with a discard writer, they
		// have a nop core, and keeping them at all seems unnecessary.
		if _, ok := l.writerOpener.(*DiscardWriter); ok {
			delete(logging.Logs, name)
			continue
		}
	}

	return nil
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Match the named log in the message and inspect the wrapped error for the root cause.
  2. Validate writer output types, encoder formats ('json', 'console'), and level strings ('DEBUG','INFO','WARN','ERROR').
  3. Test-compile filter regexes used in include/exclude.
  4. Run 'caddy adapt' plus 'caddy validate' on the config before deploying to catch this pre-start.

Example fix

// before
log mylog {
  output fille /var/log/x.log
}
// after
log mylog {
  output file /var/log/x.log
}
Defensive patterns

Strategy: validation

Try / catch

if err := cfg.Provision(ctx); err != nil {
    if e, ok := err.(error); ok && strings.Contains(e.Error(), "setting up custom log") {
        // extract log name from message, fix that log block
    }
}

Prevention

When it happens

Trigger: logging.logs.<name> with an invalid writer, an unknown encoder format string, bad include/exclude filter regexes, or an invalid level string; the error fires during Provision of that specific CustomLog.

Common situations: Caddyfile 'log <name> { ... }' blocks with a typo'd output or level; JSON with writer objects referencing modules absent from the build; regex filters that fail to compile.

Related errors


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/a322a5ba79bfd279. Report an issue: GitHub.