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