Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d6e0950

Browse files
committedDec 12, 2020
Disable logging by default
The log output is not of interest to the ordinary users, so it should only be enabled when one of the logging configuration environment variables is set.
1 parent 8d0714b commit d6e0950

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed
 

‎configuration/configuration.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
5656
}
5757
}
5858

59+
logrus.SetOutput(defaultLogOutput)
60+
5961
if logFormatString, ok := os.LookupEnv("ARDUINO_CHECK_LOG_FORMAT"); ok {
6062
logFormat, err := logFormatFromString(logFormatString)
6163
if err != nil {
6264
return fmt.Errorf("--log-format flag value %s not valid", logFormatString)
6365
}
6466
logrus.SetFormatter(logFormat)
67+
logrus.SetOutput(os.Stderr) // Enable log output.
6568
}
6669

6770
if logLevelString, ok := os.LookupEnv("ARDUINO_CHECK_LOG_LEVEL"); ok {
@@ -70,8 +73,7 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {
7073
return fmt.Errorf("--log-level flag value %s not valid", logLevelString)
7174
}
7275
logrus.SetLevel(logLevel)
73-
} else {
74-
logrus.SetLevel(defaultLogLevel)
76+
logrus.SetOutput(os.Stderr) // Enable log output.
7577
}
7678

7779
superprojectTypeFilterString, _ := flags.GetString("project-type")

‎configuration/configuration_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func TestInitializeLogFormat(t *testing.T) {
120120

121121
func TestInitializeLogLevel(t *testing.T) {
122122
require.Nil(t, Initialize(test.ConfigurationFlags(), projectPaths))
123-
assert.Equal(t, defaultLogLevel, logrus.GetLevel(), "Default level")
124123

125124
os.Setenv("ARDUINO_CHECK_LOG_LEVEL", "foo")
126125
assert.Error(t, Initialize(test.ConfigurationFlags(), projectPaths), "Invalid level")

‎configuration/defaults.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ package configuration
1818
// The default configuration settings.
1919

2020
import (
21+
"io/ioutil"
22+
2123
"github.com/arduino/arduino-check/configuration/checkmode"
2224
"github.com/arduino/arduino-check/project/projecttype"
23-
"github.com/sirupsen/logrus"
2425
)
2526

2627
// Default check modes for each superproject type.
@@ -60,4 +61,4 @@ var defaultCheckModes = map[projecttype.Type]map[checkmode.Type]bool{
6061
},
6162
}
6263

63-
var defaultLogLevel = logrus.FatalLevel
64+
var defaultLogOutput = ioutil.Discard // Default to no log output.

0 commit comments

Comments
 (0)
Please sign in to comment.