Skip to content

Commit edbac11

Browse files
committed
adding separate debug info (info + warn -> stdout, errors -> stderr) for all comands.
1 parent 09e47b9 commit edbac11

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

cmd/arduino.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ arduino login --user myUser --password # Asks to write the password inside the c
120120

121121
var testing = false
122122

123+
// ErrLogrus represents the logrus instance, which has the role to
124+
// log all non info messages.
125+
var ErrLogrus = logrus.New()
126+
123127
func init() {
124128
versions[ArduinoCmd.Name()] = ArduinoVersion
125129
InitFlags()
@@ -255,9 +259,10 @@ func IgnoreConfigs() {
255259
func arduinoPreRun(cmd *cobra.Command, args []string) {
256260
// Reset logrus if debug flag changed
257261
if !GlobalFlags.Debug { // discard logrus output if no debug
258-
logrus.SetOutput(ioutil.Discard)
262+
logrus.SetOutput(ioutil.Discard) // for standard logger
263+
ErrLogrus.Out = ioutil.Discard // for error logger
259264
} else { // else print on stderr
260-
logrus.SetOutput(os.Stderr)
265+
ErrLogrus.Out = os.Stderr
261266
}
262267
InitConfigs()
263268

@@ -359,7 +364,7 @@ func initViper() {
359364

360365
defHome, err := common.GetDefaultArduinoHomeFolder()
361366
if err != nil {
362-
logrus.WithError(err).Warn("Cannot get default Arduino Home")
367+
ErrLogrus.WithError(err).Warn("Cannot get default Arduino Home")
363368
}
364369
defArduinoData, err := common.GetDefaultArduinoFolder()
365370
if err != nil {
@@ -373,7 +378,7 @@ func initViper() {
373378
logrus.Info("Reading configuration for viper")
374379
err = viper.ReadInConfig()
375380
if err != nil {
376-
logrus.WithError(err).Error("Cannot read configuration file in any of the default folders")
381+
ErrLogrus.WithError(err).Error("Cannot read configuration file in any of the default folders")
377382
formatter.PrintErrorMessage("Cannot read configuration file in any of the default folders")
378383
os.Exit(errNoConfigFile)
379384
}
@@ -392,7 +397,7 @@ func initViper() {
392397
if viper.GetString("proxy.type") == "manual" {
393398
hostname := viper.GetString("proxy.hostname")
394399
if hostname == "" {
395-
logrus.Error("With manual proxy configuration, hostname is required.")
400+
ErrLogrus.Error("With manual proxy configuration, hostname is required.")
396401
formatter.PrintErrorMessage("With manual proxy configuration, hostname is required.")
397402
os.Exit(errCoreConfig)
398403
}
@@ -419,7 +424,7 @@ func executeLoginCommand(cmd *cobra.Command, args []string) {
419424
passwordEmpty := arduinoLoginFlags.Password == ""
420425
isTextMode := formatter.IsCurrentFormat("text")
421426
if !isTextMode && (userEmpty || passwordEmpty) {
422-
logrus.Error("User and password must be specified outside of text format")
427+
ErrLogrus.Error("User and password must be specified outside of text format")
423428
formatter.PrintErrorMessage("User and password must be specified outside of text format")
424429
return
425430
}
@@ -434,7 +439,7 @@ func executeLoginCommand(cmd *cobra.Command, args []string) {
434439
fmt.Print("Password: ")
435440
pass, err := terminal.ReadPassword(syscall.Stdin)
436441
if err != nil {
437-
logrus.WithError(err).Error("Cannot read password, login aborted")
442+
ErrLogrus.WithError(err).Error("Cannot read password, login aborted")
438443
formatter.PrintErrorMessage("Cannot read password, login aborted")
439444
return
440445
}

cmd/arduino_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func executeConfigInitCommand(cmd *cobra.Command, args []string) {
7474

7575
if !arduinoConfigInitFlags.Default {
7676
if !formatter.IsCurrentFormat("text") {
77-
logrus.Error("The interactive mode is supported only in text mode")
77+
ErrLogrus.Error("The interactive mode is supported only in text mode")
7878
formatter.PrintErrorMessage("The interactive mode is supported only in text mode")
7979
os.Exit(errBadCall)
8080
}

cmd/arduino_core.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func executeCoreDownloadCommand(cmd *cobra.Command, args []string) {
167167
logrus.Info("Executing `arduino core download`")
168168

169169
if len(args) < 1 {
170-
logrus.Error("No core specified for download command, exiting")
170+
ErrLogrus.Error("No core specified for download command, exiting")
171171
formatter.PrintErrorMessage("No core specified for download command")
172172
os.Exit(errBadCall)
173173
}
@@ -209,7 +209,7 @@ func executeCoreInstallCommand(cmd *cobra.Command, args []string) {
209209
logrus.Info("Executing `arduino core download`")
210210

211211
if len(args) < 1 {
212-
logrus.Error("No core specified for download command, exiting")
212+
ErrLogrus.Error("No core specified for download command, exiting")
213213
formatter.PrintErrorMessage("No core specified for download command")
214214
os.Exit(errBadCall)
215215
}

cmd/arduino_sketch.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ var arduinoSketchSyncCmd = &cobra.Command{
7575

7676
func executeSketchCommand(cmd *cobra.Command, args []string) {
7777
logrus.Info("Executing `arduino sketch`")
78-
logrus.Error("No subcommand specified, showing help message")
78+
ErrLogrus.Error("No subcommand specified, showing help message")
7979
formatter.PrintErrorMessage("No subcommand specified")
8080
cmd.Help()
81-
logrus.Error("Bad Call Exit")
81+
ErrLogrus.Error("Bad Call Exit")
8282
os.Exit(errBadCall)
8383
}
8484

8585
func executeSketchSyncCommand(cmd *cobra.Command, args []string) {
8686
logrus.Info("Executing `arduino sketch sync`")
8787
if len(args) > 0 {
88-
logrus.Error("No arguments are accepted for this command")
88+
ErrLogrus.Error("No arguments are accepted for this command")
8989
formatter.PrintErrorMessage("No arguments are accepted")
9090
os.Exit(errBadCall)
9191
}
@@ -104,7 +104,7 @@ func executeSketchSyncCommand(cmd *cobra.Command, args []string) {
104104

105105
if priority == "ask-once" {
106106
if !isTextMode {
107-
logrus.Error("ask mode for this command is only supported using text format")
107+
ErrLogrus.Error("ask mode for this command is only supported using text format")
108108
formatter.PrintErrorMessage("ask mode for this command is only supported using text format")
109109
os.Exit(errBadCall)
110110
}

task/concurrency.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ func ExecuteParallelFromMap(taskMap map[string]Wrapper) map[string]Result {
100100
close(results)
101101
mapResult := make(map[string]Result, len(results))
102102
for result := range results {
103-
//logrus.Errorf("results : %v %v\n", result.Key, result.Result)
104103
mapResult[result.Key] = result.Result
105104
}
106105
return mapResult

0 commit comments

Comments
 (0)