{"record":{"id":"f44719ef5ac3b6f6","repo":"XTLS/Xray-core","slug":"failed-to-initialize-error-logger","errorCode":null,"errorMessage":"failed to initialize error logger","messagePattern":"failed to initialize error logger","errorType":"console","errorClass":"errors.Error","httpStatus":null,"severity":"warning","filePath":"app/log/log.go","lineNumber":95,"sourceCode":"func (*Instance) Type() interface{} {\n\treturn (*Instance)(nil)\n}\n\nfunc (g *Instance) startInternal() error {\n\tg.Lock()\n\tdefer g.Unlock()\n\n\tif g.active {\n\t\treturn nil\n\t}\n\n\tg.active = true\n\n\tif err := g.initAccessLogger(); err != nil {\n\t\treturn errors.New(\"failed to initialize access logger\").Base(err).AtWarning()\n\t}\n\tif err := g.initErrorLogger(); err != nil {\n\t\treturn errors.New(\"failed to initialize error logger\").Base(err).AtWarning()\n\t}\n\n\treturn nil\n}\n\n// Start implements common.Runnable.Start().\nfunc (g *Instance) Start() error {\n\treturn g.startInternal()\n}\n\n// Handle implements log.Handler.\nfunc (g *Instance) Handle(msg log.Message) {\n\tg.RLock()\n\tdefer g.RUnlock()\n\n\tif !g.active {\n\t\treturn\n\t}","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/app/log/log.go#L77-L113","documentation":"Companion to error 36: initErrorLogger failed during log.Instance startup, wrapped with AtWarning so the instance still runs with error logging disabled. The chained Base error carries the actual writer creation failure.","triggerScenarios":"The error log path in config cannot be created/opened (bad directory, permissions, invalid path), or the error-log handler failed to initialize.","commonSituations":"Same file-path class of problems as the access logger: unwritable /var/log in containers, wrong ownership, directory in place of file, read-only rootfs in k8s pods.","solutions":["Inspect the Base error for the exact file operation failure","Create/chown the log directory so the xray user can write","Use a writable path or /dev/null for the error log if file logging is unwanted"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if p := cfg.Log.Error; p != \"\" && p != \"none\" {\n    if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { return err }\n    if f, err := os.OpenFile(p, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644); err != nil {\n        return fmt.Errorf(\"error log not writable: %w\", err)\n    } else { f.Close() }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Same path hygiene as access logs: writable dir, correct ownership","Check startup logs for the AtWarning line to catch silent error-log loss"],"tags":["logging","config","file-io","permissions"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}