adding ability to write a log file with all output from collector. Executing commands will now log be logged (and when debug is enabled, their output's are also logged).

This commit is contained in:
Jason Kulatunga
2020-09-19 18:51:35 -06:00
parent 67d1c592a5
commit 297f0a51c5
8 changed files with 51 additions and 9 deletions
@@ -5,6 +5,7 @@ import (
"github.com/analogj/scrutiny/collector/pkg/collector"
"github.com/analogj/scrutiny/webapp/backend/pkg/version"
"github.com/sirupsen/logrus"
"io"
"log"
"os"
"time"
@@ -85,6 +86,16 @@ OPTIONS:
logrus.SetLevel(logrus.InfoLevel)
}
if c.IsSet("log-file") {
logFile, err := os.OpenFile(c.String("log-file"), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
logrus.Errorf("Failed to open log file %s for output: %s", c.String("log-file"), err)
return err
}
defer logFile.Close()
logrus.SetOutput(io.MultiWriter(os.Stderr, logFile))
}
stCollector, err := collector.CreateSelfTestCollector(
collectorLogger,
c.String("api-endpoint"),
@@ -105,6 +116,12 @@ OPTIONS:
EnvVars: []string{"SCRUTINY_API_ENDPOINT"},
},
&cli.StringFlag{
Name: "log-file",
Usage: "Path to file for logging. Leave empty to use STDOUT",
Value: "",
},
&cli.BoolFlag{
Name: "debug",
Usage: "Enable debug logging",