From 2d9dd690c6310005d37f7961903a0afc9252bf71 Mon Sep 17 00:00:00 2001 From: Mingyang Zheng Date: Thu, 21 Nov 2024 12:36:57 -0800 Subject: [PATCH] fix(logging): Add Close() func for redirectLogger --- logger/handler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/logger/handler.go b/logger/handler.go index 7f23b32b0a6b6..6bc066658d183 100644 --- a/logger/handler.go +++ b/logger/handler.go @@ -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 +}