mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
logs: flush Logger through klog
Not all code knows that it needs to flush through component-base/logs.FlushLogs when the JSON logger is used. By registering the flush callback together with the logger, klog.Flush and klog.FlushAndExit are sufficient for flushing all data.
This commit is contained in:
parent
09aa1071cd
commit
f8bb67cc2e
@ -41,7 +41,6 @@ const deprecated = "will be removed in a future release, see https://github.com/
|
||||
|
||||
var (
|
||||
packageFlags = flag.NewFlagSet("logging", flag.ContinueOnError)
|
||||
logrFlush func()
|
||||
|
||||
// Periodic flushing gets configured either via the global flag
|
||||
// in this file or via LoggingConfiguration.
|
||||
@ -185,9 +184,6 @@ func InitLogs() {
|
||||
// are printed before exiting the program.
|
||||
func FlushLogs() {
|
||||
klog.Flush()
|
||||
if logrFlush != nil {
|
||||
logrFlush()
|
||||
}
|
||||
}
|
||||
|
||||
// NewLogger creates a new log.Logger which sends logs to klog.Info.
|
||||
|
@ -82,8 +82,7 @@ func (o *Options) apply() {
|
||||
klog.ClearLogger()
|
||||
} else {
|
||||
log, flush := factory.Create(o.Config.Options)
|
||||
klog.SetLogger(log)
|
||||
logrFlush = flush
|
||||
klog.SetLoggerWithOptions(log, klog.FlushLogger(flush))
|
||||
}
|
||||
if err := loggingFlags.Lookup("v").Value.Set(o.Config.Verbosity.String()); err != nil {
|
||||
panic(fmt.Errorf("internal error while setting klog verbosity: %v", err))
|
||||
|
Loading…
Reference in New Issue
Block a user