mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +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 (
|
var (
|
||||||
packageFlags = flag.NewFlagSet("logging", flag.ContinueOnError)
|
packageFlags = flag.NewFlagSet("logging", flag.ContinueOnError)
|
||||||
logrFlush func()
|
|
||||||
|
|
||||||
// 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.
|
||||||
@ -185,9 +184,6 @@ func InitLogs() {
|
|||||||
// are printed before exiting the program.
|
// are printed before exiting the program.
|
||||||
func FlushLogs() {
|
func FlushLogs() {
|
||||||
klog.Flush()
|
klog.Flush()
|
||||||
if logrFlush != nil {
|
|
||||||
logrFlush()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLogger creates a new log.Logger which sends logs to klog.Info.
|
// NewLogger creates a new log.Logger which sends logs to klog.Info.
|
||||||
|
@ -82,8 +82,7 @@ func (o *Options) apply() {
|
|||||||
klog.ClearLogger()
|
klog.ClearLogger()
|
||||||
} else {
|
} else {
|
||||||
log, flush := factory.Create(o.Config.Options)
|
log, flush := factory.Create(o.Config.Options)
|
||||||
klog.SetLogger(log)
|
klog.SetLoggerWithOptions(log, klog.FlushLogger(flush))
|
||||||
logrFlush = flush
|
|
||||||
}
|
}
|
||||||
if err := loggingFlags.Lookup("v").Value.Set(o.Config.Verbosity.String()); err != nil {
|
if err := loggingFlags.Lookup("v").Value.Set(o.Config.Verbosity.String()); err != nil {
|
||||||
panic(fmt.Errorf("internal error while setting klog verbosity: %v", err))
|
panic(fmt.Errorf("internal error while setting klog verbosity: %v", err))
|
||||||
|
Loading…
Reference in New Issue
Block a user