k8s.io/kubernetes@v1.29.3/test/integration/logs/benchmark/common_test.go (about) 1 /* 2 Copyright 2021 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 benchmark 18 19 import ( 20 "flag" 21 22 "k8s.io/klog/v2" 23 ) 24 25 func init() { 26 // hack/make-rules/test-integration.sh expects that all unit tests 27 // support -v and -vmodule. 28 klog.InitFlags(nil) 29 30 // Write all output into a single file. 31 flag.Set("alsologtostderr", "false") 32 flag.Set("logtostderr", "false") 33 flag.Set("one_output", "true") 34 flag.Set("stderrthreshold", "FATAL") 35 } 36 37 type bytesWritten int64 38 39 func (b *bytesWritten) Write(data []byte) (int, error) { 40 l := len(data) 41 *b += bytesWritten(l) 42 return l, nil 43 } 44 45 func printf(item logMessage) { 46 if item.isError { 47 klog.Errorf("%s: %v %s", item.msg, item.err, item.kvs) 48 } else { 49 klog.Infof("%s: %v", item.msg, item.kvs) 50 } 51 } 52 53 func prints(logger klog.Logger, item logMessage) { 54 if item.isError { 55 logger.Error(item.err, item.msg, item.kvs...) // nolint: logcheck 56 } else { 57 logger.Info(item.msg, item.kvs...) // nolint: logcheck 58 } 59 } 60 61 func printLogger(item logMessage) { 62 prints(klog.Background(), item) 63 }