grpclog.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. *
  3. * Copyright 2020 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package grpclog (internal) defines depth logging for grpc.
  19. package grpclog
  20. // Logger is the logger used for the non-depth log functions.
  21. var Logger LoggerV2
  22. // DepthLogger is the logger used for the depth log functions.
  23. var DepthLogger DepthLoggerV2
  24. // InfoDepth logs to the INFO log at the specified depth.
  25. func InfoDepth(depth int, args ...interface{}) {
  26. if DepthLogger != nil {
  27. DepthLogger.InfoDepth(depth, args...)
  28. } else {
  29. Logger.Info(args...)
  30. }
  31. }
  32. // WarningDepth logs to the WARNING log at the specified depth.
  33. func WarningDepth(depth int, args ...interface{}) {
  34. if DepthLogger != nil {
  35. DepthLogger.WarningDepth(depth, args...)
  36. } else {
  37. Logger.Warning(args...)
  38. }
  39. }
  40. // ErrorDepth logs to the ERROR log at the specified depth.
  41. func ErrorDepth(depth int, args ...interface{}) {
  42. if DepthLogger != nil {
  43. DepthLogger.ErrorDepth(depth, args...)
  44. } else {
  45. Logger.Error(args...)
  46. }
  47. }
  48. // FatalDepth logs to the FATAL log at the specified depth.
  49. func FatalDepth(depth int, args ...interface{}) {
  50. if DepthLogger != nil {
  51. DepthLogger.FatalDepth(depth, args...)
  52. } else {
  53. Logger.Fatal(args...)
  54. }
  55. }
  56. // LoggerV2 does underlying logging work for grpclog.
  57. // This is a copy of the LoggerV2 defined in the external grpclog package. It
  58. // is defined here to avoid a circular dependency.
  59. type LoggerV2 interface {
  60. // Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
  61. Info(args ...interface{})
  62. // Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.
  63. Infoln(args ...interface{})
  64. // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
  65. Infof(format string, args ...interface{})
  66. // Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.
  67. Warning(args ...interface{})
  68. // Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.
  69. Warningln(args ...interface{})
  70. // Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
  71. Warningf(format string, args ...interface{})
  72. // Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
  73. Error(args ...interface{})
  74. // Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
  75. Errorln(args ...interface{})
  76. // Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
  77. Errorf(format string, args ...interface{})
  78. // Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
  79. // gRPC ensures that all Fatal logs will exit with os.Exit(1).
  80. // Implementations may also call os.Exit() with a non-zero exit code.
  81. Fatal(args ...interface{})
  82. // Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
  83. // gRPC ensures that all Fatal logs will exit with os.Exit(1).
  84. // Implementations may also call os.Exit() with a non-zero exit code.
  85. Fatalln(args ...interface{})
  86. // Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
  87. // gRPC ensures that all Fatal logs will exit with os.Exit(1).
  88. // Implementations may also call os.Exit() with a non-zero exit code.
  89. Fatalf(format string, args ...interface{})
  90. // V reports whether verbosity level l is at least the requested verbose level.
  91. V(l int) bool
  92. }
  93. // DepthLoggerV2 logs at a specified call frame. If a LoggerV2 also implements
  94. // DepthLoggerV2, the below functions will be called with the appropriate stack
  95. // depth set for trivial functions the logger may ignore.
  96. // This is a copy of the DepthLoggerV2 defined in the external grpclog package.
  97. // It is defined here to avoid a circular dependency.
  98. //
  99. // This API is EXPERIMENTAL.
  100. type DepthLoggerV2 interface {
  101. // InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Print.
  102. InfoDepth(depth int, args ...interface{})
  103. // WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Print.
  104. WarningDepth(depth int, args ...interface{})
  105. // ErrorDetph logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Print.
  106. ErrorDepth(depth int, args ...interface{})
  107. // FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Print.
  108. FatalDepth(depth int, args ...interface{})
  109. }