grpclog.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. import (
  21. "os"
  22. )
  23. // Logger is the logger used for the non-depth log functions.
  24. var Logger LoggerV2
  25. // DepthLogger is the logger used for the depth log functions.
  26. var DepthLogger DepthLoggerV2
  27. // InfoDepth logs to the INFO log at the specified depth.
  28. func InfoDepth(depth int, args ...interface{}) {
  29. if DepthLogger != nil {
  30. DepthLogger.InfoDepth(depth, args...)
  31. } else {
  32. Logger.Infoln(args...)
  33. }
  34. }
  35. // WarningDepth logs to the WARNING log at the specified depth.
  36. func WarningDepth(depth int, args ...interface{}) {
  37. if DepthLogger != nil {
  38. DepthLogger.WarningDepth(depth, args...)
  39. } else {
  40. Logger.Warningln(args...)
  41. }
  42. }
  43. // ErrorDepth logs to the ERROR log at the specified depth.
  44. func ErrorDepth(depth int, args ...interface{}) {
  45. if DepthLogger != nil {
  46. DepthLogger.ErrorDepth(depth, args...)
  47. } else {
  48. Logger.Errorln(args...)
  49. }
  50. }
  51. // FatalDepth logs to the FATAL log at the specified depth.
  52. func FatalDepth(depth int, args ...interface{}) {
  53. if DepthLogger != nil {
  54. DepthLogger.FatalDepth(depth, args...)
  55. } else {
  56. Logger.Fatalln(args...)
  57. }
  58. os.Exit(1)
  59. }
  60. // LoggerV2 does underlying logging work for grpclog.
  61. // This is a copy of the LoggerV2 defined in the external grpclog package. It
  62. // is defined here to avoid a circular dependency.
  63. type LoggerV2 interface {
  64. // Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
  65. Info(args ...interface{})
  66. // Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.
  67. Infoln(args ...interface{})
  68. // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
  69. Infof(format string, args ...interface{})
  70. // Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.
  71. Warning(args ...interface{})
  72. // Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.
  73. Warningln(args ...interface{})
  74. // Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
  75. Warningf(format string, args ...interface{})
  76. // Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
  77. Error(args ...interface{})
  78. // Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
  79. Errorln(args ...interface{})
  80. // Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
  81. Errorf(format string, args ...interface{})
  82. // Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
  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. Fatal(args ...interface{})
  86. // Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println.
  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. Fatalln(args ...interface{})
  90. // Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
  91. // gRPC ensures that all Fatal logs will exit with os.Exit(1).
  92. // Implementations may also call os.Exit() with a non-zero exit code.
  93. Fatalf(format string, args ...interface{})
  94. // V reports whether verbosity level l is at least the requested verbose level.
  95. V(l int) bool
  96. }
  97. // DepthLoggerV2 logs at a specified call frame. If a LoggerV2 also implements
  98. // DepthLoggerV2, the below functions will be called with the appropriate stack
  99. // depth set for trivial functions the logger may ignore.
  100. // This is a copy of the DepthLoggerV2 defined in the external grpclog package.
  101. // It is defined here to avoid a circular dependency.
  102. //
  103. // # Experimental
  104. //
  105. // Notice: This type is EXPERIMENTAL and may be changed or removed in a
  106. // later release.
  107. type DepthLoggerV2 interface {
  108. // InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Println.
  109. InfoDepth(depth int, args ...interface{})
  110. // WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Println.
  111. WarningDepth(depth int, args ...interface{})
  112. // ErrorDepth logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Println.
  113. ErrorDepth(depth int, args ...interface{})
  114. // FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println.
  115. FatalDepth(depth int, args ...interface{})
  116. }