{"record":{"id":"03637cf059991cd6","repo":"XTLS/Xray-core","slug":"unable-to-get-logger-instance","errorCode":null,"errorMessage":"unable to get logger instance","messagePattern":"unable to get logger instance","errorType":"exception","errorClass":"errors.Error","httpStatus":null,"severity":"warning","filePath":"app/log/command/command.go","lineNumber":21,"sourceCode":"import (\n\t\"context\"\n\n\t\"github.com/xtls/xray-core/app/log\"\n\t\"github.com/xtls/xray-core/common\"\n\t\"github.com/xtls/xray-core/common/errors\"\n\t\"github.com/xtls/xray-core/core\"\n\tgrpc \"google.golang.org/grpc\"\n)\n\ntype LoggerServer struct {\n\tV *core.Instance\n}\n\n// RestartLogger implements LoggerService.\nfunc (s *LoggerServer) RestartLogger(ctx context.Context, request *RestartLoggerRequest) (*RestartLoggerResponse, error) {\n\tlogger := s.V.GetFeature((*log.Instance)(nil))\n\tif logger == nil {\n\t\treturn nil, errors.New(\"unable to get logger instance\")\n\t}\n\tif err := logger.Close(); err != nil {\n\t\treturn nil, errors.New(\"failed to close logger\").Base(err)\n\t}\n\tif err := logger.Start(); err != nil {\n\t\treturn nil, errors.New(\"failed to start logger\").Base(err)\n\t}\n\treturn &RestartLoggerResponse{}, nil\n}\n\nfunc (s *LoggerServer) mustEmbedUnimplementedLoggerServiceServer() {}\n\ntype service struct {\n\tv *core.Instance\n}\n\nfunc (s *service) Register(server *grpc.Server) {\n\tls := &LoggerServer{","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/app/log/command/command.go#L3-L39","documentation":"Returned by the gRPC LoggerService RestartLogger handler when s.V.GetFeature((*log.Instance)(nil)) yields nil — the running core instance has no log app registered, so there is nothing to restart.","triggerScenarios":"Calling the xray API RestartLogger endpoint on an instance whose log app was never registered (log disabled in config or the app omitted from the build).","commonSituations":"Setting loglevel to 'none'/removing the log section and still issuing API restarts; third-party panels calling RestartLogger unconditionally against minimal instances.","solutions":["Enable the log app in the instance config (a log block with a valid loglevel) before calling RestartLogger","Have API callers treat this as a benign no-op condition when logging is intentionally disabled","Verify with a GetStats/log status call that the log feature exists before restarting"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// API clients should first confirm the log feature exists:\n// (equivalent server-side check)\nif s.V.GetFeature((*log.Instance)(nil)) == nil {\n    return nil, errors.New(\"unable to get logger instance\")\n}","typeGuard":"func hasLogger(v *core.Instance) bool {\n    return v.GetFeature((*log.Instance)(nil)) != nil\n}","tryCatchPattern":"resp, err := loggerClient.RestartLogger(ctx, &RestartLoggerRequest{})\nif err != nil && strings.Contains(err.Error(), \"unable to get logger instance\") {\n    // logging disabled on the instance: safe to ignore\n}","preventionTips":["Keep a log block enabled in configs that expose the logger API","Panels should probe for the feature before calling RestartLogger"],"tags":["api","grpc","logging","feature-registration"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}