logs: simplify flush daemon startup

StartFlushDaemon can be called more than once. We can take advantage of that an
eliminate the tracking of where we need to start it.
This commit is contained in:
Patrick Ohly 2022-04-01 15:31:03 +02:00
parent 4033e64bf1
commit 18bf5d23f1

View File

@ -44,7 +44,6 @@ var (
// Periodic flushing gets configured either via the global flag // Periodic flushing gets configured either via the global flag
// in this file or via LoggingConfiguration. // in this file or via LoggingConfiguration.
logFlushFreq time.Duration logFlushFreq time.Duration
logFlushFreqAdded bool
) )
func init() { func init() {
@ -100,7 +99,6 @@ func AddFlags(fs *pflag.FlagSet, opts ...Option) {
if o.skipLoggingConfigurationFlags { if o.skipLoggingConfigurationFlags {
return return
} }
logFlushFreqAdded = true
case "vmodule": case "vmodule":
// TODO: see above // TODO: see above
// pf.Usage += vmoduleUsage // pf.Usage += vmoduleUsage
@ -142,7 +140,6 @@ func AddGoFlags(fs *flag.FlagSet, opts ...Option) {
if o.skipLoggingConfigurationFlags { if o.skipLoggingConfigurationFlags {
return return
} }
logFlushFreqAdded = true
case "vmodule": case "vmodule":
// TODO: see above // TODO: see above
// usage += vmoduleUsage // usage += vmoduleUsage
@ -181,11 +178,11 @@ func (writer KlogWriter) Write(data []byte) (n int, err error) {
func InitLogs() { func InitLogs() {
log.SetOutput(KlogWriter{}) log.SetOutput(KlogWriter{})
log.SetFlags(0) log.SetFlags(0)
if logFlushFreqAdded {
// The flag from this file was activated, so use it now. // Start flushing now. If LoggingConfiguration.ApplyAndValidate is
// Otherwise LoggingConfiguration.Apply will do this. // used, it will restart the daemon with the log flush interval defined
// there.
klog.StartFlushDaemon(logFlushFreq) klog.StartFlushDaemon(logFlushFreq)
}
// This is the default in Kubernetes. Options.ValidateAndApply // This is the default in Kubernetes. Options.ValidateAndApply
// will override this with the result of a feature gate check. // will override this with the result of a feature gate check.