{"record":{"id":"c182f97e921604aa","repo":"caddyserver/caddy","slug":"setting-up-default-caddy-log-v","errorCode":null,"errorMessage":"setting up default Caddy log: %v","messagePattern":"setting up default Caddy log: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"logging.go","lineNumber":151,"sourceCode":"\n\treturn nil\n}\n\nfunc (logging *Logging) setupNewDefault(ctx Context) error {\n\tif logging.Logs == nil {\n\t\tlogging.Logs = make(map[string]*CustomLog)\n\t}\n\n\t// extract the user-defined default log, if any\n\tnewDefault := new(defaultCustomLog)\n\tif userDefault, ok := logging.Logs[DefaultLoggerName]; ok {\n\t\tnewDefault.CustomLog = userDefault\n\t} else {\n\t\t// if none, make one with our own default settings\n\t\tvar err error\n\t\tnewDefault, err = newDefaultProductionLog()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"setting up default Caddy log: %v\", err)\n\t\t}\n\t\tlogging.Logs[DefaultLoggerName] = newDefault.CustomLog\n\t}\n\n\t// options for the default logger\n\toptions, err := newDefault.CustomLog.buildOptions()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"setting up default log: %v\", err)\n\t}\n\n\t// set up this new log\n\terr = newDefault.CustomLog.provision(ctx, logging)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"setting up default log: %v\", err)\n\t}\n\n\tfilteringCore := &filteringCore{newDefault.CustomLog.core, newDefault.CustomLog}\n\tnewDefault.logger = zap.New(filteringCore, options...)","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/logging.go#L133-L169","documentation":"When no user-defined default log exists, Caddy constructs its production default log via newDefaultProductionLog. Failure there (building default options, opening the default writer) surfaces as this error during Logging setup.","triggerScenarios":"Rare: the default production writer (stderr) cannot be opened — e.g. stderr closed/invalid in the process environment — or internal option building fails. Triggered inside setupNewDefault when DefaultLoggerName is absent from logging.Logs.","commonSituations":"Running Caddy as a service where stderr was closed or redirected to an invalid descriptor; unusual container runtimes detaching stderr; extremely constrained environments.","solutions":["Ensure the process has a valid stderr (service unit with StandardError=journal or a file).","Define an explicit default log (\"log\" with name default) with a concrete writer such as file, so the production stderr default is not needed.","Check the wrapped error for the precise failing step."],"exampleFix":"// before: no default log, stderr unusable\n// after: explicit default log to file\n\"logging\": { \"logs\": { \"default\": { \"writer\": { \"output\": \"file\", \"filename\": \"/var/log/caddy.log\" } } } }","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define an explicit default log with a file writer when stderr is unreliable.","Service units should keep a valid StandardError target."],"tags":["logging","default","provision","environment"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}