fix(logging): Add Close() func for redirectLogger (#16219)

This commit is contained in:
Mingyang Zheng 2024-11-25 02:26:09 -08:00 committed by GitHub
parent 3dea61cb5c
commit 16401c73cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions

View File

@ -125,3 +125,13 @@ func (l *redirectLogger) Print(level telegraf.LogLevel, ts time.Time, prefix str
msg := append([]interface{}{ts.In(time.UTC).Format(time.RFC3339), " ", level.Indicator(), " ", prefix + attrMsg}, args...)
fmt.Fprintln(l.writer, msg...)
}
func (l *redirectLogger) Close() error {
if l.writer == os.Stderr {
return nil
}
if closer, ok := l.writer.(io.Closer); ok {
return closer.Close()
}
return nil
}