forked from golang/glog
-
Notifications
You must be signed in to change notification settings - Fork 227
InitFlags does not reset klog configuration if application already did logging #67
Copy link
Copy link
Open
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.Indicates that an issue or PR should not be auto-closed due to staleness.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.Important over the long term, but may not be staffed and/or may need multiple releases to complete.
Metadata
Metadata
Assignees
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.Indicates that an issue or PR should not be auto-closed due to staleness.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.Important over the long term, but may not be staffed and/or may need multiple releases to complete.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Needs Triage
/kind bug
What steps did you take and what happened:
klog.InitFlags(nil)andflag.Parse(). Flags specify log file.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:
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.