logger.go 2.1 KB

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