Change:
What would you like to be : As part of should add logging configuration allowing to change logging implementation. Things to implement: --logging-format - flag to pick between available implementations. Defaults to "text" using unchanged klog. LoggingConfig - structure storing component configuration for logging LogFormatRegistry - Used for registration of additional log formats. New formats should be registered by providing unique name and implementation of interface LoggingConfig.Complete method should configure klog by passing logr interface implementation into klog.SetLogger method Why is this needed: Subtask of /help /wg component-standard
The klog 1.0.0 version looks like no SetLogger method, should update klog version in vendor?
yes, forgot about that. I remember saying that it will require some changes, but shouldn't be to hard. I will help with it if needed.
/assign /remove-help
Klog was upgraded to v2.

Discussion:
require ( github.com/blang/semver v3.5.0+incompatible <ins> github.com/go-logr/logr v0.1.0 </ins> github.com/google/go-cmp v0.4.0 github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect

go_library( name = "go_default_library", <del> srcs = ["logs.go"], </del> <ins> srcs = [ "logs.go", "options.go", "registry.go", ], </ins> importmap = "k8s.io/kubernetes/vendor/k8s.io/component-base/logs", importpath = "k8s.io/component-base/logs", deps = [ "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", <ins> "//vendor/github.com/go-logr/logr:go_default_library", </ins> "//vendor/github.com/spf13/pflag:go_default_library", "//vendor/k8s.io/klog/v2:go_default_library", ],

<ins> /* Copyright 2020 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package logs import ( "fmt" "github.com/go-logr/logr" "github.com/spf13/pflag" "k8s.io/klog/v2" ) const ( logFormatFlagName = "logging-format" defaultLogFormat  = "text" ) // Options has klog format parameters type Options struct { LogFormat string } // NewOptions return new klog options func NewOptions() *Options { return &Options{ LogFormat: defaultLogFormat, } } // Validate check LogFormat in registry or not func (o *Options) Validate() []error { if _, err := o.Get(); err != nil { return []error{fmt.Errorf("unsupported log format: %s", o.LogFormat)} } return nil } // AddFlags add logging-format flag func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.LogFormat, logFormatFlagName, defaultLogFormat, "Set log format") } // Apply set klog logger from LogFormat type func (o *Options) Apply() { // if log format not exists, use nil loggr loggr, _ := o.Get() klog.SetLogger(loggr) } // Get logger with LogFormat field func (o *Options) Get() (logr.Logger, error) { return logRegistry.Get(o.LogFormat) } </ins>

<ins> /* Copyright 2020 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package logs import ( "fmt" "sync" "github.com/go-logr/logr" ) var logRegistry = NewLogFormatRegistry() // LogFormatRegistry store klog format registry type LogFormatRegistry struct { registry map[string]logr.Logger mu       sync.Mutex } // NewLogFormatRegistry return new init LogFormatRegistry struct func NewLogFormatRegistry() *LogFormatRegistry { return &LogFormatRegistry{ registry: make(map[string]logr.Logger), mu:       sync.Mutex{}, } } // Register new log format registry to global logRegistry func (lfr *LogFormatRegistry) Register(name string, logger logr.Logger) error { lfr.mu.Lock() defer lfr.mu.Unlock() if _, ok := lfr.registry[name]; ok { return fmt.Errorf("log format: %s already exists", name) } lfr.registry[name] = logger return nil } // Get specified log format logger func (lfr *LogFormatRegistry) Get(name string) (logr.Logger, error) { lfr.mu.Lock() defer lfr.mu.Unlock() re, ok := lfr.registry[name] if !ok { return nil, fmt.Errorf("log format: %s does not exists", name) } return re, nil } // Set specified log format logger func (lfr *LogFormatRegistry) Set(name string, logger logr.Logger) { lfr.mu.Lock() defer lfr.mu.Unlock() lfr.registry[name] = logger } // Delete specified log format logger func (lfr *LogFormatRegistry) Delete(name string) { lfr.mu.Lock() defer lfr.mu.Unlock() delete(lfr.registry, name) } func init() { // Text format is default klog format logRegistry.Register("text", nil) } </ins>