1
0

rpclogger.go 1.8 KB

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