github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/app/log/command/command.go (about)

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