Skip to content

Commit c6acd8e

Browse files
committed
feat: change default verbosity level to error instead of warn
Signed-off-by: Brian McGee <brian@bmcgee.ie>
1 parent 2dcfe67 commit c6acd8e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

cmd/format/format.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func Run(v *viper.Viper, statz *stats.Stats, cmd *cobra.Command, paths []string)
197197
return fmt.Errorf("failed to close walker: %w", err)
198198
}
199199

200-
// print stats to stdout, unless we are processing from stdin and therefore outputting the results to stdout
201-
if !cfg.Stdin {
200+
// print stats to stdout unless we are processing from stdin or verbosity level is lower than info (1)
201+
if !cfg.Stdin && cfg.Verbose > 0 {
202202
statz.Print()
203203
}
204204

cmd/root.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ func runE(v *viper.Viper, statz *stats.Stats, cmd *cobra.Command, args []string)
131131
return fmt.Errorf("failed to find treefmt config file: %w", err)
132132
}
133133

134-
log.Infof("using config file: %s", configFile)
135-
136134
// read in the config
137135
v.SetConfigFile(configFile)
138136

@@ -144,15 +142,21 @@ func runE(v *viper.Viper, statz *stats.Stats, cmd *cobra.Command, args []string)
144142
log.SetOutput(os.Stderr)
145143
log.SetReportTimestamp(false)
146144

145+
// set log level based on verbosity
146+
// by default we only emit errors
147147
switch v.GetInt("verbose") {
148148
case 0:
149-
log.SetLevel(log.WarnLevel)
149+
log.SetLevel(log.ErrorLevel)
150150
case 1:
151+
log.SetLevel(log.WarnLevel)
152+
case 2:
151153
log.SetLevel(log.InfoLevel)
152154
default:
153155
log.SetLevel(log.DebugLevel)
154156
}
155157

158+
log.Infof("using config file: %s", configFile)
159+
156160
// format
157161
return format.Run(v, statz, cmd, args) //nolint:wrapcheck
158162
}

cmd/root_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestOnUnmatched(t *testing.T) {
7474

7575
// default is WARN
7676
t.Run("default", func(t *testing.T) {
77-
treefmt(t, withNoError(t), withOutput(checkOutput(log.WarnLevel)))
77+
treefmt(t, withArgs("-v"), withNoError(t), withOutput(checkOutput(log.WarnLevel)))
7878
})
7979

8080
// should exit with error when using fatal
@@ -97,15 +97,15 @@ func TestOnUnmatched(t *testing.T) {
9797
as.NoError(err, "failed to parse log level: %s", level)
9898

9999
treefmt(t,
100-
withArgs("-vv", "--on-unmatched", levelStr),
100+
withArgs("-vvv", "--on-unmatched", levelStr),
101101
withNoError(t),
102102
withOutput(checkOutput(level)),
103103
)
104104

105105
t.Setenv("TREEFMT_ON_UNMATCHED", levelStr)
106106

107107
treefmt(t,
108-
withArgs("-vv"),
108+
withArgs("-vvv"),
109109
withNoError(t),
110110
withOutput(checkOutput(level)),
111111
)

0 commit comments

Comments
 (0)