@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"io/ioutil"
23
23
"os"
24
+ "strings"
24
25
25
26
"github.com/arduino/arduino-cli/cli/board"
26
27
"github.com/arduino/arduino-cli/cli/compile"
51
52
PersistentPreRun : preRun ,
52
53
}
53
54
54
- verbose bool
55
- logFile string
55
+ verbose bool
56
+ logFile string
57
+ logFormat string
56
58
)
57
59
58
60
const (
@@ -80,6 +82,7 @@ func createCliCommandTree(cmd *cobra.Command) {
80
82
cmd .PersistentFlags ().BoolVarP (& verbose , "verbose" , "v" , false , "Print the logs on the standard output." )
81
83
cmd .PersistentFlags ().StringVar (& globals .LogLevel , "log-level" , defaultLogLevel , "Messages with this level and above will be logged (default: warn)." )
82
84
cmd .PersistentFlags ().StringVar (& logFile , "log-file" , "" , "Path to the file where logs will be written." )
85
+ cmd .PersistentFlags ().StringVar (& logFormat , "log-format" , "text" , "The output format for the logs, can be [text|json]." )
83
86
cmd .PersistentFlags ().StringVar (& globals .OutputFormat , "format" , "text" , "The output format, can be [text|json]." )
84
87
cmd .PersistentFlags ().StringVar (& globals .YAMLConfigFile , "config-file" , "" , "The custom config file (if not specified the default will be used)." )
85
88
cmd .PersistentFlags ().StringSliceVar (& globals .AdditionalUrls , "additional-urls" , []string {}, "Additional URLs for the board manager." )
@@ -102,6 +105,7 @@ func toLogLevel(s string) (t logrus.Level, found bool) {
102
105
}
103
106
104
107
func parseFormatString (arg string ) (feedback.OutputFormat , bool ) {
108
+ arg = strings .ToLower (arg )
105
109
f , found := map [string ]feedback.OutputFormat {
106
110
"json" : feedback .JSON ,
107
111
"text" : feedback .Text ,
@@ -151,6 +155,11 @@ func preRun(cmd *cobra.Command, args []string) {
151
155
feedback .SetFormat (f )
152
156
}
153
157
158
+ // set the Logger format
159
+ if strings .ToLower (logFormat ) == "json" {
160
+ logrus .SetFormatter (& logrus.JSONFormatter {})
161
+ }
162
+
154
163
globals .InitConfigs ()
155
164
156
165
logrus .Info (globals .VersionInfo .Application + "-" + globals .VersionInfo .VersionString )
0 commit comments