@@ -120,6 +120,10 @@ arduino login --user myUser --password # Asks to write the password inside the c
120
120
121
121
var testing = false
122
122
123
+ // ErrLogrus represents the logrus instance, which has the role to
124
+ // log all non info messages.
125
+ var ErrLogrus = logrus .New ()
126
+
123
127
func init () {
124
128
versions [ArduinoCmd .Name ()] = ArduinoVersion
125
129
InitFlags ()
@@ -255,9 +259,10 @@ func IgnoreConfigs() {
255
259
func arduinoPreRun (cmd * cobra.Command , args []string ) {
256
260
// Reset logrus if debug flag changed
257
261
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
259
264
} else { // else print on stderr
260
- logrus . SetOutput ( os .Stderr )
265
+ ErrLogrus . Out = os .Stderr
261
266
}
262
267
InitConfigs ()
263
268
@@ -359,7 +364,7 @@ func initViper() {
359
364
360
365
defHome , err := common .GetDefaultArduinoHomeFolder ()
361
366
if err != nil {
362
- logrus .WithError (err ).Warn ("Cannot get default Arduino Home" )
367
+ ErrLogrus .WithError (err ).Warn ("Cannot get default Arduino Home" )
363
368
}
364
369
defArduinoData , err := common .GetDefaultArduinoFolder ()
365
370
if err != nil {
@@ -373,7 +378,7 @@ func initViper() {
373
378
logrus .Info ("Reading configuration for viper" )
374
379
err = viper .ReadInConfig ()
375
380
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" )
377
382
formatter .PrintErrorMessage ("Cannot read configuration file in any of the default folders" )
378
383
os .Exit (errNoConfigFile )
379
384
}
@@ -392,7 +397,7 @@ func initViper() {
392
397
if viper .GetString ("proxy.type" ) == "manual" {
393
398
hostname := viper .GetString ("proxy.hostname" )
394
399
if hostname == "" {
395
- logrus .Error ("With manual proxy configuration, hostname is required." )
400
+ ErrLogrus .Error ("With manual proxy configuration, hostname is required." )
396
401
formatter .PrintErrorMessage ("With manual proxy configuration, hostname is required." )
397
402
os .Exit (errCoreConfig )
398
403
}
@@ -419,7 +424,7 @@ func executeLoginCommand(cmd *cobra.Command, args []string) {
419
424
passwordEmpty := arduinoLoginFlags .Password == ""
420
425
isTextMode := formatter .IsCurrentFormat ("text" )
421
426
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" )
423
428
formatter .PrintErrorMessage ("User and password must be specified outside of text format" )
424
429
return
425
430
}
@@ -434,7 +439,7 @@ func executeLoginCommand(cmd *cobra.Command, args []string) {
434
439
fmt .Print ("Password: " )
435
440
pass , err := terminal .ReadPassword (syscall .Stdin )
436
441
if err != nil {
437
- logrus .WithError (err ).Error ("Cannot read password, login aborted" )
442
+ ErrLogrus .WithError (err ).Error ("Cannot read password, login aborted" )
438
443
formatter .PrintErrorMessage ("Cannot read password, login aborted" )
439
444
return
440
445
}
0 commit comments