rpclogger.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package internal
  2. import (
  3. "sync"
  4. "github.com/tal-tech/go-zero/core/logx"
  5. "google.golang.org/grpc/grpclog"
  6. )
  7. // because grpclog.errorLog is not exported, we need to define our own.
  8. const errorLevel = 2
  9. var once sync.Once
  10. type Logger struct{}
  11. func InitLogger() {
  12. once.Do(func() {
  13. grpclog.SetLoggerV2(new(Logger))
  14. })
  15. }
  16. func (l *Logger) Error(args ...interface{}) {
  17. logx.Error(args...)
  18. }
  19. func (l *Logger) Errorf(format string, args ...interface{}) {
  20. logx.Errorf(format, args...)
  21. }
  22. func (l *Logger) Errorln(args ...interface{}) {
  23. logx.Error(args...)
  24. }
  25. func (l *Logger) Fatal(args ...interface{}) {
  26. logx.Error(args...)
  27. }
  28. func (l *Logger) Fatalf(format string, args ...interface{}) {
  29. logx.Errorf(format, args...)
  30. }
  31. func (l *Logger) Fatalln(args ...interface{}) {
  32. logx.Error(args...)
  33. }
  34. func (l *Logger) Info(args ...interface{}) {
  35. // ignore builtin grpc info
  36. }
  37. func (l *Logger) Infoln(args ...interface{}) {
  38. // ignore builtin grpc info
  39. }
  40. func (l *Logger) Infof(format string, args ...interface{}) {
  41. // ignore builtin grpc info
  42. }
  43. func (l *Logger) V(v int) bool {
  44. return v >= errorLevel
  45. }
  46. func (l *Logger) Warning(args ...interface{}) {
  47. // ignore builtin grpc warning
  48. }
  49. func (l *Logger) Warningf(format string, args ...interface{}) {
  50. // ignore builtin grpc warning
  51. }
  52. func (l *Logger) Warningln(args ...interface{}) {
  53. // ignore builtin grpc warning
  54. }