log.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2020 Envoyproxy Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package log provides a logging interface for use in this library.
  15. package log
  16. // Logger interface for reporting informational and warning messages.
  17. type Logger interface {
  18. // Debugf logs a formatted debugging message.
  19. Debugf(format string, args ...interface{})
  20. // Infof logs a formatted informational message.
  21. Infof(format string, args ...interface{})
  22. // Warnf logs a formatted warning message.
  23. Warnf(format string, args ...interface{})
  24. // Errorf logs a formatted error message.
  25. Errorf(format string, args ...interface{})
  26. }
  27. // LoggerFuncs implements the Logger interface, allowing the
  28. // caller to specify only the logging functions that are desired.
  29. type LoggerFuncs struct {
  30. DebugFunc func(string, ...interface{})
  31. InfoFunc func(string, ...interface{})
  32. WarnFunc func(string, ...interface{})
  33. ErrorFunc func(string, ...interface{})
  34. }
  35. // Debugf logs a formatted debugging message.
  36. func (f LoggerFuncs) Debugf(format string, args ...interface{}) {
  37. if f.DebugFunc != nil {
  38. f.DebugFunc(format, args...)
  39. }
  40. }
  41. // Infof logs a formatted informational message.
  42. func (f LoggerFuncs) Infof(format string, args ...interface{}) {
  43. if f.InfoFunc != nil {
  44. f.InfoFunc(format, args...)
  45. }
  46. }
  47. // Warnf logs a formatted warning message.
  48. func (f LoggerFuncs) Warnf(format string, args ...interface{}) {
  49. if f.WarnFunc != nil {
  50. f.WarnFunc(format, args...)
  51. }
  52. }
  53. // Errorf logs a formatted error message.
  54. func (f LoggerFuncs) Errorf(format string, args ...interface{}) {
  55. if f.ErrorFunc != nil {
  56. f.ErrorFunc(format, args...)
  57. }
  58. }