@@ -120,6 +120,10 @@ arduino login --user myUser --password # Asks to write the password inside the c
120120
121121var 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+
123127func init () {
124128 versions [ArduinoCmd .Name ()] = ArduinoVersion
125129 InitFlags ()
@@ -255,9 +259,10 @@ func IgnoreConfigs() {
255259func 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 }
0 commit comments