go-zero/zrpc/internal/rpclogger.go

82 lines
1.8 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 (
"github.com/zeromicro/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
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{}
2022-10-06 23:57:56 +08:00
func init() {
grpclog.SetLoggerV2(new(Logger))
2020-07-26 17:09:05 +08:00
}
2021-03-01 23:52:44 +08:00
// Error logs the given args into error log.
func (l *Logger) Error(args ...any) {
2020-07-26 17:09:05 +08:00
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Errorf logs the given args with format into error log.
func (l *Logger) Errorf(format string, args ...any) {
2020-07-26 17:09:05 +08:00
logx.Errorf(format, args...)
}
2021-03-01 23:52:44 +08:00
// Errorln logs the given args into error log with newline.
func (l *Logger) Errorln(args ...any) {
2020-07-26 17:09:05 +08:00
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Fatal logs the given args into error log.
func (l *Logger) Fatal(args ...any) {
2020-07-26 17:09:05 +08:00
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Fatalf logs the given args with format into error log.
func (l *Logger) Fatalf(format string, args ...any) {
2020-07-26 17:09:05 +08:00
logx.Errorf(format, args...)
}
2021-03-01 23:52:44 +08:00
// Fatalln logs args into error log with newline.
func (l *Logger) Fatalln(args ...any) {
2020-07-26 17:09:05 +08:00
logx.Error(args...)
}
2021-03-01 23:52:44 +08:00
// Info ignores the grpc info logs.
2024-03-09 13:48:11 +08:00
func (l *Logger) Info(_ ...any) {
2020-07-26 17:09:05 +08:00
// ignore builtin grpc info
}
2021-03-01 23:52:44 +08:00
// Infoln ignores the grpc info logs.
2024-03-09 13:48:11 +08:00
func (l *Logger) Infoln(_ ...any) {
2020-07-26 17:09:05 +08:00
// ignore builtin grpc info
}
2021-03-01 23:52:44 +08:00
// Infof ignores the grpc info logs.
2024-03-09 13:48:11 +08:00
func (l *Logger) Infof(_ string, _ ...any) {
2020-07-26 17:09:05 +08:00
// 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.
2024-03-09 13:48:11 +08:00
func (l *Logger) Warning(_ ...any) {
2020-07-26 17:09:05 +08:00
// ignore builtin grpc warning
}
2021-03-01 23:52:44 +08:00
// Warningf ignores the grpc warning logs.
2024-03-09 13:48:11 +08:00
func (l *Logger) Warningf(_ string, _ ...any) {
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.
2024-03-09 13:48:11 +08:00
func (l *Logger) Warningln(_ ...any) {
2020-07-26 17:09:05 +08:00
// ignore builtin grpc warning
}