logging.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. *
  3. * Copyright 2020 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 channelz
  19. import (
  20. "fmt"
  21. "google.golang.org/grpc/grpclog"
  22. )
  23. var logger = grpclog.Component("channelz")
  24. func withParens(id *Identifier) string {
  25. return "[" + id.String() + "] "
  26. }
  27. // Info logs and adds a trace event if channelz is on.
  28. func Info(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) {
  29. AddTraceEvent(l, id, 1, &TraceEventDesc{
  30. Desc: fmt.Sprint(args...),
  31. Severity: CtInfo,
  32. })
  33. }
  34. // Infof logs and adds a trace event if channelz is on.
  35. func Infof(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...interface{}) {
  36. AddTraceEvent(l, id, 1, &TraceEventDesc{
  37. Desc: fmt.Sprintf(format, args...),
  38. Severity: CtInfo,
  39. })
  40. }
  41. // Warning logs and adds a trace event if channelz is on.
  42. func Warning(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) {
  43. AddTraceEvent(l, id, 1, &TraceEventDesc{
  44. Desc: fmt.Sprint(args...),
  45. Severity: CtWarning,
  46. })
  47. }
  48. // Warningf logs and adds a trace event if channelz is on.
  49. func Warningf(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...interface{}) {
  50. AddTraceEvent(l, id, 1, &TraceEventDesc{
  51. Desc: fmt.Sprintf(format, args...),
  52. Severity: CtWarning,
  53. })
  54. }
  55. // Error logs and adds a trace event if channelz is on.
  56. func Error(l grpclog.DepthLoggerV2, id *Identifier, args ...interface{}) {
  57. AddTraceEvent(l, id, 1, &TraceEventDesc{
  58. Desc: fmt.Sprint(args...),
  59. Severity: CtError,
  60. })
  61. }
  62. // Errorf logs and adds a trace event if channelz is on.
  63. func Errorf(l grpclog.DepthLoggerV2, id *Identifier, format string, args ...interface{}) {
  64. AddTraceEvent(l, id, 1, &TraceEventDesc{
  65. Desc: fmt.Sprintf(format, args...),
  66. Severity: CtError,
  67. })
  68. }