discard.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. Copyright 2020 The logr Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package logr
  14. // Discard returns a valid Logger that discards all messages logged to it.
  15. // It can be used whenever the caller is not interested in the logs.
  16. func Discard() Logger {
  17. return DiscardLogger{}
  18. }
  19. // DiscardLogger is a Logger that discards all messages.
  20. type DiscardLogger struct{}
  21. func (l DiscardLogger) Enabled() bool {
  22. return false
  23. }
  24. func (l DiscardLogger) Info(msg string, keysAndValues ...interface{}) {
  25. }
  26. func (l DiscardLogger) Error(err error, msg string, keysAndValues ...interface{}) {
  27. }
  28. func (l DiscardLogger) V(level int) Logger {
  29. return l
  30. }
  31. func (l DiscardLogger) WithValues(keysAndValues ...interface{}) Logger {
  32. return l
  33. }
  34. func (l DiscardLogger) WithName(name string) Logger {
  35. return l
  36. }
  37. // Verify that it actually implements the interface
  38. var _ Logger = DiscardLogger{}