glogger.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 glogger defines glog-based logging for grpc.
  19. // Importing this package will install glog as the logger used by grpclog.
  20. package glogger
  21. import (
  22. "fmt"
  23. "github.com/golang/glog"
  24. "google.golang.org/grpc/grpclog"
  25. )
  26. const d = 2
  27. func init() {
  28. grpclog.SetLoggerV2(&glogger{})
  29. }
  30. type glogger struct{}
  31. func (g *glogger) Info(args ...interface{}) {
  32. glog.InfoDepth(d, args...)
  33. }
  34. func (g *glogger) Infoln(args ...interface{}) {
  35. glog.InfoDepth(d, fmt.Sprintln(args...))
  36. }
  37. func (g *glogger) Infof(format string, args ...interface{}) {
  38. glog.InfoDepth(d, fmt.Sprintf(format, args...))
  39. }
  40. func (g *glogger) InfoDepth(depth int, args ...interface{}) {
  41. glog.InfoDepth(depth+d, args...)
  42. }
  43. func (g *glogger) Warning(args ...interface{}) {
  44. glog.WarningDepth(d, args...)
  45. }
  46. func (g *glogger) Warningln(args ...interface{}) {
  47. glog.WarningDepth(d, fmt.Sprintln(args...))
  48. }
  49. func (g *glogger) Warningf(format string, args ...interface{}) {
  50. glog.WarningDepth(d, fmt.Sprintf(format, args...))
  51. }
  52. func (g *glogger) WarningDepth(depth int, args ...interface{}) {
  53. glog.WarningDepth(depth+d, args...)
  54. }
  55. func (g *glogger) Error(args ...interface{}) {
  56. glog.ErrorDepth(d, args...)
  57. }
  58. func (g *glogger) Errorln(args ...interface{}) {
  59. glog.ErrorDepth(d, fmt.Sprintln(args...))
  60. }
  61. func (g *glogger) Errorf(format string, args ...interface{}) {
  62. glog.ErrorDepth(d, fmt.Sprintf(format, args...))
  63. }
  64. func (g *glogger) ErrorDepth(depth int, args ...interface{}) {
  65. glog.ErrorDepth(depth+d, args...)
  66. }
  67. func (g *glogger) Fatal(args ...interface{}) {
  68. glog.FatalDepth(d, args...)
  69. }
  70. func (g *glogger) Fatalln(args ...interface{}) {
  71. glog.FatalDepth(d, fmt.Sprintln(args...))
  72. }
  73. func (g *glogger) Fatalf(format string, args ...interface{}) {
  74. glog.FatalDepth(d, fmt.Sprintf(format, args...))
  75. }
  76. func (g *glogger) FatalDepth(depth int, args ...interface{}) {
  77. glog.FatalDepth(depth+d, args...)
  78. }
  79. func (g *glogger) V(l int) bool {
  80. return bool(glog.V(glog.Level(l)))
  81. }