-
Notifications
You must be signed in to change notification settings - Fork 227
Description
/kind bug
What steps did you take and what happened:
- Application uses klog.Infof()
- Logging happens based on klog default configuration.
- Application calls
klog.InitFlags(nil)andflag.Parse(). Flags specify log file. - Application uses klog.Infof() again.
- Logs are NOT appended to output file specified by flags
What did you expect to happen:
Ideally klog should properly reinitialize itself to configuration specified via flags on (4) and log from (5) should be appended to the log file.
Alternatively klog could disallows calling InitFlag() after logging was done before (panic?).
Yet this is suboptimal as one not always can prevent logging from happening before InitFlags. As logging can occur in init function of some dependent module.
Anything else you would like to add:
The source of described problem lies in behavior of createFiles (https://github.com/kubernetes/klog/blob/master/klog.go#L968). This method is called on first logging and log appenders are created then and put in logging.files array. Those are not reset later even if configuration changes.
Actually the situation is even more confusing than that. As appenders are created only for log levels up to requested one, we end up in inconsistent state of klog in following sequence of events:
- klog.Infof
- InitFlags
- klog.ErrorF
Then the appenders for DEBUG and INFO will be based on default configuration. And appender for ERROR will take configuration changes from flags into account.
I spotted the problem when playing with flag related to log file but possibly one can run into issues with other flags too.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status