logger.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. *
  3. * Copyright 2015 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
  19. import "google.golang.org/grpc/internal/grpclog"
  20. // Logger mimics golang's standard Logger as an interface.
  21. //
  22. // Deprecated: use LoggerV2.
  23. type Logger interface {
  24. Fatal(args ...interface{})
  25. Fatalf(format string, args ...interface{})
  26. Fatalln(args ...interface{})
  27. Print(args ...interface{})
  28. Printf(format string, args ...interface{})
  29. Println(args ...interface{})
  30. }
  31. // SetLogger sets the logger that is used in grpc. Call only from
  32. // init() functions.
  33. //
  34. // Deprecated: use SetLoggerV2.
  35. func SetLogger(l Logger) {
  36. grpclog.Logger = &loggerWrapper{Logger: l}
  37. }
  38. // loggerWrapper wraps Logger into a LoggerV2.
  39. type loggerWrapper struct {
  40. Logger
  41. }
  42. func (g *loggerWrapper) Info(args ...interface{}) {
  43. g.Logger.Print(args...)
  44. }
  45. func (g *loggerWrapper) Infoln(args ...interface{}) {
  46. g.Logger.Println(args...)
  47. }
  48. func (g *loggerWrapper) Infof(format string, args ...interface{}) {
  49. g.Logger.Printf(format, args...)
  50. }
  51. func (g *loggerWrapper) Warning(args ...interface{}) {
  52. g.Logger.Print(args...)
  53. }
  54. func (g *loggerWrapper) Warningln(args ...interface{}) {
  55. g.Logger.Println(args...)
  56. }
  57. func (g *loggerWrapper) Warningf(format string, args ...interface{}) {
  58. g.Logger.Printf(format, args...)
  59. }
  60. func (g *loggerWrapper) Error(args ...interface{}) {
  61. g.Logger.Print(args...)
  62. }
  63. func (g *loggerWrapper) Errorln(args ...interface{}) {
  64. g.Logger.Println(args...)
  65. }
  66. func (g *loggerWrapper) Errorf(format string, args ...interface{}) {
  67. g.Logger.Printf(format, args...)
  68. }
  69. func (g *loggerWrapper) V(l int) bool {
  70. // Returns true for all verbose level.
  71. return true
  72. }