github.com/shuguocloud/go-zero@v1.3.0/zrpc/internal/rpclogger.go (about)

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