go-zero/zrpc/internal/rpclogger.go

89 lines
2.0 KiB
Go
Raw Normal View History

2020-07-29 18:06:57 +08:00
package internal
2020-07-26 17:09:05 +08:00
import (
"sync"
2020-08-08 16:40:10 +08:00
"github.com/tal-tech/go-zero/core/logx"
2020-07-26 17:09:05 +08:00
"google.golang.org/grpc/grpclog"
)
// because grpclog.errorLog is not exported, we need to define our own.
const errorLevel = 2
var once sync.Once
2021-03-01 23:52:44 +08:00
// A Logger is a rpc logger.
2020-07-26 17:09:05 +08:00
type Logger struct{}
2021-03-01 23:52:44 +08:00
// InitLogger initializes the rpc logger.
2020-07-26 17:09:05 +08:00
func InitLogger() {
once.Do(func() {
grpclog.SetLoggerV2(new(Logger))
})
}
2021-03-01 23:52:44 +08:00
// Error logs the given args into error log.
2020-07-26 17:09:05 +08:00
func (l *Logger) Error(args ...interface{}) {
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Errorf logs the given args with format into error log.
2020-07-26 17:09:05 +08:00
func (l *Logger) Errorf(format string, args ...interface{}) {
logx.Errorf(format, args...)
}
2021-03-01 23:52:44 +08:00
// Errorln logs the given args into error log with newline.
2020-07-26 17:09:05 +08:00
func (l *Logger) Errorln(args ...interface{}) {
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Fatal logs the given args into error log.
2020-07-26 17:09:05 +08:00
func (l *Logger) Fatal(args ...interface{}) {
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Fatalf logs the given args with format into error log.
2020-07-26 17:09:05 +08:00
func (l *Logger) Fatalf(format string, args ...interface{}) {
logx.Errorf(format, args...)
}
2021-03-01 23:52:44 +08:00
// Fatalln logs args into error log with newline.
2020-07-26 17:09:05 +08:00
func (l *Logger) Fatalln(args ...interface{}) {
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Info ignores the grpc info logs.
2020-07-26 17:09:05 +08:00
func (l *Logger) Info(args ...interface{}) {
// ignore builtin grpc info
}
2021-03-01 23:52:44 +08:00
// Infoln ignores the grpc info logs.
2020-07-26 17:09:05 +08:00
func (l *Logger) Infoln(args ...interface{}) {
// ignore builtin grpc info
}
2021-03-01 23:52:44 +08:00
// Infof ignores the grpc info logs.
2020-07-26 17:09:05 +08:00
func (l *Logger) Infof(format string, args ...interface{}) {
// ignore builtin grpc info
}
2021-03-01 23:52:44 +08:00
// V checks if meet required log level.
2020-07-26 17:09:05 +08:00
func (l *Logger) V(v int) bool {
return v >= errorLevel
}
2021-03-01 23:52:44 +08:00
// Warning ignores the grpc warning logs.
2020-07-26 17:09:05 +08:00
func (l *Logger) Warning(args ...interface{}) {
// ignore builtin grpc warning
}
2021-03-01 23:52:44 +08:00
// Warningf ignores the grpc warning logs.
2020-12-27 14:08:24 +08:00
func (l *Logger) Warningf(format string, args ...interface{}) {
2020-07-26 17:09:05 +08:00
// ignore builtin grpc warning
}
2021-03-01 23:52:44 +08:00
// Warningln ignores the grpc warning logs.
2020-12-27 14:08:24 +08:00
func (l *Logger) Warningln(args ...interface{}) {
2020-07-26 17:09:05 +08:00
// ignore builtin grpc warning
}