From da890d95b68a953352db49b4bb3b2288578ecad8 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sun, 25 Apr 2021 11:34:26 -0700 Subject: [PATCH] Fixing forced logging of smartctl output irrespective of log level (now available at DEBUG level only) TODO: add a table summary at INFO level. fixes #123 --- collector/pkg/common/exec.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/collector/pkg/common/exec.go b/collector/pkg/common/exec.go index b17ea22..085107a 100644 --- a/collector/pkg/common/exec.go +++ b/collector/pkg/common/exec.go @@ -15,7 +15,15 @@ func ExecCmd(logger *logrus.Entry, cmdName string, cmdArgs []string, workingDir cmd := exec.Command(cmdName, cmdArgs...) var stdBuffer bytes.Buffer - mw := io.MultiWriter(logger.Logger.Out, &stdBuffer) + + logWriters := []io.Writer{ + &stdBuffer, + } + if logger.Logger.Level == logrus.DebugLevel { + logWriters = append(logWriters, logger.Logger.Out) + } + + mw := io.MultiWriter(logWriters...) cmd.Stdout = mw cmd.Stderr = mw