Skip to content

logging during init #3707

@pohly

Description

@pohly

The following log output is redundant and potentially confusing:

func RegisterPlugin(name string, plugin Plugin) error {
pluginsLock.Lock()
defer pluginsLock.Unlock()
if _, found := plugins[name]; found {
return fmt.Errorf("Plugin %q was registered twice", name)
}
klog.V(4).Infof("Registered Plugin %q", name)

RegisterPlugin gets called during init, for example in

err := container.RegisterPlugin("containerd", containerd.NewPlugin())

During init, klog verbosity is either zero (making the log call redundant because it doesn't print anything) or some other init function reconfigures logging, in which case the output is potentially confusing because it is not guaranteed that logging is reconfigured before the plugin install functions.

I ran into this when experimenting with the logging configuration in the Kubernetes test/e2e suite. I got log output for "containerd", but not for "systemd" and "crio", although those were also registered in the process (confirmed in a debugger).

In other scenarios, flag parsing might switch from klog text format to something else entirely, which then leads to a mixture of text and e.g. JSON output. In general, code running during init should not log.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions