1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package log 18 19 import ( 20 "github.com/go-logr/logr" 21 ) 22 23 // NB: this is the same as the null logger logr/testing, 24 // but avoids accidentally adding the testing flags to 25 // all binaries. 26 27 // NullLogSink is a logr.Logger that does nothing. 28 type NullLogSink struct{} 29 30 var _ logr.LogSink = NullLogSink{} 31 32 // Init implements logr.LogSink. 33 func (log NullLogSink) Init(logr.RuntimeInfo) { 34 } 35 36 // Info implements logr.InfoLogger. 37 func (NullLogSink) Info(_ int, _ string, _ ...interface{}) { 38 // Do nothing. 39 } 40 41 // Enabled implements logr.InfoLogger. 42 func (NullLogSink) Enabled(level int) bool { 43 return false 44 } 45 46 // Error implements logr.Logger. 47 func (NullLogSink) Error(_ error, _ string, _ ...interface{}) { 48 // Do nothing. 49 } 50 51 // WithName implements logr.Logger. 52 func (log NullLogSink) WithName(_ string) logr.LogSink { 53 return log 54 } 55 56 // WithValues implements logr.Logger. 57 func (log NullLogSink) WithValues(_ ...interface{}) logr.LogSink { 58 return log 59 } 60