caddyserver/caddy · error

configuring default format for encoder module: %v

Error message

configuring default format for encoder module: %v

What it means

Some encoder modules implement ConfiguresFormatterDefault so they can pick a sensible nested-encoder default based on the writer (e.g. console-style formatting only when writing to a terminal-like writer). This error is thrown when that secondary provisioning step, ConfigureDefaultFormat(cl.writerOpener), returns an error.

Source

Thrown at logging.go:377

	// set up the log level
	cl.levelEnabler, err = parseLevel(cl.Level)
	if err != nil {
		return err
	}

	if cl.EncoderRaw != nil {
		mod, err := ctx.LoadModule(cl, "EncoderRaw")
		if err != nil {
			return fmt.Errorf("loading log encoder module: %v", err)
		}
		cl.encoder = mod.(zapcore.Encoder)

		// if the encoder module needs the writer to determine
		// the correct default to use for a nested encoder, we
		// pass it down as a secondary provisioning step
		if cfd, ok := mod.(ConfiguresFormatterDefault); ok {
			if err := cfd.ConfigureDefaultFormat(cl.writerOpener); err != nil {
				return fmt.Errorf("configuring default format for encoder module: %v", err)
			}
		}
	}
	if cl.encoder == nil {
		cl.encoder = newDefaultProductionLogEncoder(cl.writerOpener)
	}
	cl.buildCore()
	if cl.CoreRaw != nil {
		mod, err := ctx.LoadModule(cl, "CoreRaw")
		if err != nil {
			return fmt.Errorf("loading log core module: %v", err)
		}
		core := mod.(zapcore.Core)
		cl.core = zapcore.NewTee(cl.core, core)
	}
	return nil
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Inspect the wrapped error to see which default-format decision failed.
  2. Specify the nested format explicitly instead of relying on the writer-derived default.
  3. Match the encoder to the writer type (e.g. use json/console encoders with file or stderr writers).
  4. If the encoder is third-party, check its compatibility matrix with the writer module you configured.

Example fix

// before (caddyfile)
log {
    output net localhost:9000
    encoder filter {
        wrap console
    }
}

// after — pin the nested format explicitly
log {
    output net localhost:9000
    encoder filter {
        wrap json
    }
}
Defensive patterns

Strategy: validation

Try / catch

if err := caddy.Validate(cfg); err != nil {
    if strings.Contains(err.Error(), "configuring default format for encoder module") {
        // set an explicit nested format and retry validation
    }
    return err
}

Prevention

When it happens

Trigger: An encoder module that implements ConfiguresFormatterDefault (such as the filter encoder wrapping a formatter) fails while deciding its default sub-format — typically because the writer type is incompatible with the required default or the wrapped configuration is invalid.

Common situations: Using the filter encoder with a nested format that cannot be combined with the chosen writer; third-party encoders whose default-format logic rejects non-file or non-console writers; upgrades that changed which encoders implement the interface.

Related errors


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