Skip to content

Commit ef27958

Browse files
committed
Disable logging immediately
By default, logging is disabled, but this was previously done in configuration.Initialize(), meaning that any log output above the default level made before that part of the configuration ran was still displayed.
1 parent 9092c41 commit ef27958

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

configuration/configuration.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package configuration
1818

1919
import (
2020
"fmt"
21+
"io/ioutil"
2122
"os"
2223
"strconv"
2324
"strings"
@@ -56,15 +57,13 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
5657
}
5758
}
5859

59-
logrus.SetOutput(defaultLogOutput)
60-
6160
if logFormatString, ok := os.LookupEnv("ARDUINO_CHECK_LOG_FORMAT"); ok {
6261
logFormat, err := logFormatFromString(logFormatString)
6362
if err != nil {
6463
return fmt.Errorf("--log-format flag value %s not valid", logFormatString)
6564
}
6665
logrus.SetFormatter(logFormat)
67-
logrus.SetOutput(os.Stderr) // Enable log output.
66+
EnableLogging(true)
6867
}
6968

7069
if logLevelString, ok := os.LookupEnv("ARDUINO_CHECK_LOG_LEVEL"); ok {
@@ -73,7 +72,7 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
7372
return fmt.Errorf("--log-level flag value %s not valid", logLevelString)
7473
}
7574
logrus.SetLevel(logLevel)
76-
logrus.SetOutput(os.Stderr) // Enable log output.
75+
EnableLogging(true)
7776
}
7877

7978
superprojectTypeFilterString, _ := flags.GetString("project-type")
@@ -232,3 +231,11 @@ func SchemasPath() *paths.Path {
232231
}
233232
return paths.New(executablePath).Parent().Join("etc", "schemas")
234233
}
234+
235+
func EnableLogging(enable bool) {
236+
if enable {
237+
logrus.SetOutput(defaultLogOutput) // Enable log output.
238+
} else {
239+
logrus.SetOutput(ioutil.Discard)
240+
}
241+
}

configuration/defaults.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package configuration
1818
// The default configuration settings.
1919

2020
import (
21-
"io/ioutil"
21+
"os"
2222

2323
"github.com/arduino/arduino-check/configuration/checkmode"
2424
"github.com/arduino/arduino-check/project/projecttype"
@@ -61,4 +61,4 @@ var defaultCheckModes = map[projecttype.Type]map[checkmode.Type]bool{
6161
},
6262
}
6363

64-
var defaultLogOutput = ioutil.Discard // Default to no log output.
64+
var defaultLogOutput = os.Stderr

main.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ import (
1919
"os"
2020

2121
"github.com/arduino/arduino-check/cli"
22+
"github.com/arduino/arduino-check/configuration"
2223
"github.com/arduino/arduino-check/result/feedback"
2324
)
2425

26+
func init() {
27+
configuration.EnableLogging(false)
28+
}
29+
2530
func main() {
2631
rootCommand := cli.Root()
2732
if err := rootCommand.Execute(); err != nil {

0 commit comments

Comments
 (0)