github.com/xraypb/xray-core@v1.6.6/app/log/command/command.go (about) 1 package command 2 3 //go:generate go run github.com/xraypb/xray-core/common/errors/errorgen 4 5 import ( 6 "context" 7 8 "github.com/xraypb/xray-core/app/log" 9 "github.com/xraypb/xray-core/common" 10 "github.com/xraypb/xray-core/core" 11 grpc "google.golang.org/grpc" 12 ) 13 14 type LoggerServer struct { 15 V *core.Instance 16 } 17 18 // RestartLogger implements LoggerService. 19 func (s *LoggerServer) RestartLogger(ctx context.Context, request *RestartLoggerRequest) (*RestartLoggerResponse, error) { 20 logger := s.V.GetFeature((*log.Instance)(nil)) 21 if logger == nil { 22 return nil, newError("unable to get logger instance") 23 } 24 if err := logger.Close(); err != nil { 25 return nil, newError("failed to close logger").Base(err) 26 } 27 if err := logger.Start(); err != nil { 28 return nil, newError("failed to start logger").Base(err) 29 } 30 return &RestartLoggerResponse{}, nil 31 } 32 33 func (s *LoggerServer) mustEmbedUnimplementedLoggerServiceServer() {} 34 35 type service struct { 36 v *core.Instance 37 } 38 39 func (s *service) Register(server *grpc.Server) { 40 ls := &LoggerServer{ 41 V: s.v, 42 } 43 RegisterLoggerServiceServer(server, ls) 44 45 // For compatibility purposes 46 vCoreDesc := LoggerService_ServiceDesc 47 vCoreDesc.ServiceName = "v2ray.core.app.log.command.LoggerService" 48 server.RegisterService(&vCoreDesc, ls) 49 } 50 51 func init() { 52 common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) { 53 s := core.MustFromContext(ctx) 54 return &service{v: s}, nil 55 })) 56 }