{"record":{"id":"30c56d59a6dee27b","repo":"caddyserver/caddy","slug":"configuring-default-format-for-encoder-module-v","errorCode":null,"errorMessage":"configuring default format for encoder module: %v","messagePattern":"configuring default format for encoder module: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"logging.go","lineNumber":377,"sourceCode":"\t// set up the log level\n\tcl.levelEnabler, err = parseLevel(cl.Level)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif cl.EncoderRaw != nil {\n\t\tmod, err := ctx.LoadModule(cl, \"EncoderRaw\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"loading log encoder module: %v\", err)\n\t\t}\n\t\tcl.encoder = mod.(zapcore.Encoder)\n\n\t\t// if the encoder module needs the writer to determine\n\t\t// the correct default to use for a nested encoder, we\n\t\t// pass it down as a secondary provisioning step\n\t\tif cfd, ok := mod.(ConfiguresFormatterDefault); ok {\n\t\t\tif err := cfd.ConfigureDefaultFormat(cl.writerOpener); err != nil {\n\t\t\t\treturn fmt.Errorf(\"configuring default format for encoder module: %v\", err)\n\t\t\t}\n\t\t}\n\t}\n\tif cl.encoder == nil {\n\t\tcl.encoder = newDefaultProductionLogEncoder(cl.writerOpener)\n\t}\n\tcl.buildCore()\n\tif cl.CoreRaw != nil {\n\t\tmod, err := ctx.LoadModule(cl, \"CoreRaw\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"loading log core module: %v\", err)\n\t\t}\n\t\tcore := mod.(zapcore.Core)\n\t\tcl.core = zapcore.NewTee(cl.core, core)\n\t}\n\treturn nil\n}\n","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/logging.go#L359-L395","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped error to see which default-format decision failed.","Specify the nested format explicitly instead of relying on the writer-derived default.","Match the encoder to the writer type (e.g. use json/console encoders with file or stderr writers).","If the encoder is third-party, check its compatibility matrix with the writer module you configured."],"exampleFix":"// before (caddyfile)\nlog {\n    output net localhost:9000\n    encoder filter {\n        wrap console\n    }\n}\n\n// after — pin the nested format explicitly\nlog {\n    output net localhost:9000\n    encoder filter {\n        wrap json\n    }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := caddy.Validate(cfg); err != nil {\n    if strings.Contains(err.Error(), \"configuring default format for encoder module\") {\n        // set an explicit nested format and retry validation\n    }\n    return err\n}","preventionTips":["Always pin the nested format inside composite encoders (filter { wrap json }) instead of relying on writer-derived defaults.","Match encoder families to writer families (file/stderr vs net) when composing configs.","Test log configs after any Caddy upgrade — the ConfiguresFormatterDefault behavior set can change."],"tags":["logging","encoder","module-system"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}