grpclog.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. *
  3. * Copyright 2017 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 defines logging for grpc.
  19. //
  20. // All logs in transport package only go to verbose level 2.
  21. // All logs in other packages in grpc are logged in spite of the verbosity level.
  22. //
  23. // In the default logger,
  24. // severity level can be set by environment variable GRPC_GO_LOG_SEVERITY_LEVEL,
  25. // verbosity level can be set by GRPC_GO_LOG_VERBOSITY_LEVEL.
  26. package grpclog // import "google.golang.org/grpc/grpclog"
  27. import "os"
  28. var logger = newLoggerV2()
  29. // V reports whether verbosity level l is at least the requested verbose level.
  30. func V(l int) bool {
  31. return logger.V(l)
  32. }
  33. // Info logs to the INFO log.
  34. func Info(args ...interface{}) {
  35. logger.Info(args...)
  36. }
  37. // Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf.
  38. func Infof(format string, args ...interface{}) {
  39. logger.Infof(format, args...)
  40. }
  41. // Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println.
  42. func Infoln(args ...interface{}) {
  43. logger.Infoln(args...)
  44. }
  45. // Warning logs to the WARNING log.
  46. func Warning(args ...interface{}) {
  47. logger.Warning(args...)
  48. }
  49. // Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf.
  50. func Warningf(format string, args ...interface{}) {
  51. logger.Warningf(format, args...)
  52. }
  53. // Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println.
  54. func Warningln(args ...interface{}) {
  55. logger.Warningln(args...)
  56. }
  57. // Error logs to the ERROR log.
  58. func Error(args ...interface{}) {
  59. logger.Error(args...)
  60. }
  61. // Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf.
  62. func Errorf(format string, args ...interface{}) {
  63. logger.Errorf(format, args...)
  64. }
  65. // Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println.
  66. func Errorln(args ...interface{}) {
  67. logger.Errorln(args...)
  68. }
  69. // Fatal logs to the FATAL log. Arguments are handled in the manner of fmt.Print.
  70. // It calls os.Exit() with exit code 1.
  71. func Fatal(args ...interface{}) {
  72. logger.Fatal(args...)
  73. // Make sure fatal logs will exit.
  74. os.Exit(1)
  75. }
  76. // Fatalf logs to the FATAL log. Arguments are handled in the manner of fmt.Printf.
  77. // It calles os.Exit() with exit code 1.
  78. func Fatalf(format string, args ...interface{}) {
  79. logger.Fatalf(format, args...)
  80. // Make sure fatal logs will exit.
  81. os.Exit(1)
  82. }
  83. // Fatalln logs to the FATAL log. Arguments are handled in the manner of fmt.Println.
  84. // It calle os.Exit()) with exit code 1.
  85. func Fatalln(args ...interface{}) {
  86. logger.Fatalln(args...)
  87. // Make sure fatal logs will exit.
  88. os.Exit(1)
  89. }
  90. // Print prints to the logger. Arguments are handled in the manner of fmt.Print.
  91. //
  92. // Deprecated: use Info.
  93. func Print(args ...interface{}) {
  94. logger.Info(args...)
  95. }
  96. // Printf prints to the logger. Arguments are handled in the manner of fmt.Printf.
  97. //
  98. // Deprecated: use Infof.
  99. func Printf(format string, args ...interface{}) {
  100. logger.Infof(format, args...)
  101. }
  102. // Println prints to the logger. Arguments are handled in the manner of fmt.Println.
  103. //
  104. // Deprecated: use Infoln.
  105. func Println(args ...interface{}) {
  106. logger.Infoln(args...)
  107. }