github.com/eagleql/xray-core@v1.4.4/app/log/command/command.go (about)

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