grpclog.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 and grpclb packages 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 (
  28. "os"
  29. "google.golang.org/grpc/internal/grpclog"
  30. )
  31. func init() {
  32. SetLoggerV2(newLoggerV2())
  33. }
  34. // V reports whether verbosity level l is at least the requested verbose level.
  35. func V(l int) bool {
  36. return grpclog.Logger.V(l)
  37. }
  38. // Info logs to the INFO log.
  39. func Info(args ...interface{}) {
  40. grpclog.Logger.Info(args...)
  41. }
  42. // Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf.
  43. func Infof(format string, args ...interface{}) {
  44. grpclog.Logger.Infof(format, args...)
  45. }
  46. // Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println.
  47. func Infoln(args ...interface{}) {
  48. grpclog.Logger.Infoln(args...)
  49. }
  50. // Warning logs to the WARNING log.
  51. func Warning(args ...interface{}) {
  52. grpclog.Logger.Warning(args...)
  53. }
  54. // Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf.
  55. func Warningf(format string, args ...interface{}) {
  56. grpclog.Logger.Warningf(format, args...)
  57. }
  58. // Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println.
  59. func Warningln(args ...interface{}) {
  60. grpclog.Logger.Warningln(args...)
  61. }
  62. // Error logs to the ERROR log.
  63. func Error(args ...interface{}) {
  64. grpclog.Logger.Error(args...)
  65. }
  66. // Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf.
  67. func Errorf(format string, args ...interface{}) {
  68. grpclog.Logger.Errorf(format, args...)
  69. }
  70. // Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println.
  71. func Errorln(args ...interface{}) {
  72. grpclog.Logger.Errorln(args...)
  73. }
  74. // Fatal logs to the FATAL log. Arguments are handled in the manner of fmt.Print.
  75. // It calls os.Exit() with exit code 1.
  76. func Fatal(args ...interface{}) {
  77. grpclog.Logger.Fatal(args...)
  78. // Make sure fatal logs will exit.
  79. os.Exit(1)
  80. }
  81. // Fatalf logs to the FATAL log. Arguments are handled in the manner of fmt.Printf.
  82. // It calls os.Exit() with exit code 1.
  83. func Fatalf(format string, args ...interface{}) {
  84. grpclog.Logger.Fatalf(format, args...)
  85. // Make sure fatal logs will exit.
  86. os.Exit(1)
  87. }
  88. // Fatalln logs to the FATAL log. Arguments are handled in the manner of fmt.Println.
  89. // It calle os.Exit()) with exit code 1.
  90. func Fatalln(args ...interface{}) {
  91. grpclog.Logger.Fatalln(args...)
  92. // Make sure fatal logs will exit.
  93. os.Exit(1)
  94. }
  95. // Print prints to the logger. Arguments are handled in the manner of fmt.Print.
  96. //
  97. // Deprecated: use Info.
  98. func Print(args ...interface{}) {
  99. grpclog.Logger.Info(args...)
  100. }
  101. // Printf prints to the logger. Arguments are handled in the manner of fmt.Printf.
  102. //
  103. // Deprecated: use Infof.
  104. func Printf(format string, args ...interface{}) {
  105. grpclog.Logger.Infof(format, args...)
  106. }
  107. // Println prints to the logger. Arguments are handled in the manner of fmt.Println.
  108. //
  109. // Deprecated: use Infoln.
  110. func Println(args ...interface{}) {
  111. grpclog.Logger.Infoln(args...)
  112. }