{"record":{"id":"a322a5ba79bfd279","repo":"caddyserver/caddy","slug":"setting-up-custom-log-s-v","errorCode":null,"errorMessage":"setting up custom log '%s': %v","messagePattern":"setting up custom log '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"logging.go","lineNumber":117,"sourceCode":"\t\t\treturn fmt.Errorf(\"setting up sink log: %v\", err)\n\t\t}\n\t}\n\n\t// as a special case, set up the default structured Caddy log next\n\tif err := logging.setupNewDefault(ctx); err != nil {\n\t\treturn err\n\t}\n\n\t// then set up any other custom logs\n\tfor name, l := range logging.Logs {\n\t\t// the default log is already set up\n\t\tif name == DefaultLoggerName {\n\t\t\tcontinue\n\t\t}\n\n\t\terr := l.provision(ctx, logging)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"setting up custom log '%s': %v\", name, err)\n\t\t}\n\n\t\t// Any other logs that use the discard writer can be deleted\n\t\t// entirely. This avoids encoding and processing of each\n\t\t// log entry that would just be thrown away anyway. Notably,\n\t\t// we do not reach this point for the default log, which MUST\n\t\t// exist, otherwise core log emissions would panic because\n\t\t// they use the Log() function directly which expects a non-nil\n\t\t// logger. Even if we keep logs with a discard writer, they\n\t\t// have a nop core, and keeping them at all seems unnecessary.\n\t\tif _, ok := l.writerOpener.(*DiscardWriter); ok {\n\t\t\tdelete(logging.Logs, name)\n\t\t\tcontinue\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/logging.go#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Match the named log in the message and inspect the wrapped error for the root cause.","Validate writer output types, encoder formats ('json', 'console'), and level strings ('DEBUG','INFO','WARN','ERROR').","Test-compile filter regexes used in include/exclude.","Run 'caddy adapt' plus 'caddy validate' on the config before deploying to catch this pre-start."],"exampleFix":"// before\nlog mylog {\n  output fille /var/log/x.log\n}\n// after\nlog mylog {\n  output file /var/log/x.log\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := cfg.Provision(ctx); err != nil {\n    if e, ok := err.(error); ok && strings.Contains(e.Error(), \"setting up custom log\") {\n        // extract log name from message, fix that log block\n    }\n}","preventionTips":["Give each custom log a distinct name so errors are attributable.","Validate encoder/level/filter fields per current Caddy docs."],"tags":["logging","provision","config","caddyfile"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}