{"record":{"id":"82b93b6c1d5bd607","repo":"XTLS/Xray-core","slug":"failed-to-initialize-access-logger","errorCode":null,"errorMessage":"failed to initialize access logger","messagePattern":"failed to initialize access logger","errorType":"console","errorClass":"errors.Error","httpStatus":null,"severity":"warning","filePath":"app/log/log.go","lineNumber":92,"sourceCode":"}\n\n// Type implements common.HasType.\nfunc (*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","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/app/log/log.go#L74-L110","documentation":"Raised by log.Instance.startInternal when initAccessLogger fails: creating the handler for the configured access log (file writer or formatter) returned an error, which is chained. Marked AtWarning because Xray continues running with access logging disabled rather than crashing.","triggerScenarios":"Config sets an access log path whose file cannot be created or opened (missing directory, EACCES, name too long), or an access log handler type that fails to initialize.","commonSituations":"Running as a non-root user with access log pointed at /var/log/xray; log directory not created in Docker images; SELinux denying writes; leftover path pointing to a directory instead of a file.","solutions":["Read the chained Base error to identify the file error (ENOENT vs EACCES)","Create the log directory and grant write permission to the xray process user (e.g. mkdir -p /var/log/xray && chown)","Point access logs to a path that exists and is writable, or use an empty path to disable access logging"],"exampleFix":"// before\n\"log\": { \"access\": \"/var/log/xray/access.log\" } // dir missing, EACCES\n// after (shell)\n// mkdir -p /var/log/xray && chown xray:xray /var/log/xray","handlingStrategy":"validation","validationCode":"// At startup, before instance start, verify the access log path is writable:\nif p := cfg.Log.Access; 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(\"access log not writable: %w\", err)\n    } else { f.Close() }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create and chown log directories in the service unit/container entrypoint","Validate log paths during config review","Remember this error is AtWarning — Xray runs on, but without access logs"],"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"}