github.com/lingyao2333/mo-zero@v1.4.1/zrpc/internal/rpclogger.go (about)

     1  package internal
     2  
     3  import (
     4  	"github.com/lingyao2333/mo-zero/core/logx"
     5  	"google.golang.org/grpc/grpclog"
     6  )
     7  
     8  // because grpclog.errorLog is not exported, we need to define our own.
     9  const errorLevel = 2
    10  
    11  // A Logger is a rpc logger.
    12  type Logger struct{}
    13  
    14  func init() {
    15  	grpclog.SetLoggerV2(new(Logger))
    16  }
    17  
    18  // Error logs the given args into error log.
    19  func (l *Logger) Error(args ...interface{}) {
    20  	logx.Error(args...)
    21  }
    22  
    23  // Errorf logs the given args with format into error log.
    24  func (l *Logger) Errorf(format string, args ...interface{}) {
    25  	logx.Errorf(format, args...)
    26  }
    27  
    28  // Errorln logs the given args into error log with newline.
    29  func (l *Logger) Errorln(args ...interface{}) {
    30  	logx.Error(args...)
    31  }
    32  
    33  // Fatal logs the given args into error log.
    34  func (l *Logger) Fatal(args ...interface{}) {
    35  	logx.Error(args...)
    36  }
    37  
    38  // Fatalf logs the given args with format into error log.
    39  func (l *Logger) Fatalf(format string, args ...interface{}) {
    40  	logx.Errorf(format, args...)
    41  }
    42  
    43  // Fatalln logs args into error log with newline.
    44  func (l *Logger) Fatalln(args ...interface{}) {
    45  	logx.Error(args...)
    46  }
    47  
    48  // Info ignores the grpc info logs.
    49  func (l *Logger) Info(args ...interface{}) {
    50  	// ignore builtin grpc info
    51  }
    52  
    53  // Infoln ignores the grpc info logs.
    54  func (l *Logger) Infoln(args ...interface{}) {
    55  	// ignore builtin grpc info
    56  }
    57  
    58  // Infof ignores the grpc info logs.
    59  func (l *Logger) Infof(format string, args ...interface{}) {
    60  	// ignore builtin grpc info
    61  }
    62  
    63  // V checks if meet required log level.
    64  func (l *Logger) V(v int) bool {
    65  	return v >= errorLevel
    66  }
    67  
    68  // Warning ignores the grpc warning logs.
    69  func (l *Logger) Warning(args ...interface{}) {
    70  	// ignore builtin grpc warning
    71  }
    72  
    73  // Warningf ignores the grpc warning logs.
    74  func (l *Logger) Warningf(format string, args ...interface{}) {
    75  	// ignore builtin grpc warning
    76  }
    77  
    78  // Warningln ignores the grpc warning logs.
    79  func (l *Logger) Warningln(args ...interface{}) {
    80  	// ignore builtin grpc warning
    81  }