@@ -105,7 +105,6 @@ func toLogLevel(s string) (t logrus.Level, found bool) {
105
105
}
106
106
107
107
func parseFormatString (arg string ) (feedback.OutputFormat , bool ) {
108
- arg = strings .ToLower (arg )
109
108
f , found := map [string ]feedback.OutputFormat {
110
109
"json" : feedback .JSON ,
111
110
"text" : feedback .Text ,
@@ -115,6 +114,10 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
115
114
}
116
115
117
116
func preRun (cmd * cobra.Command , args []string ) {
117
+ // normalize the format strings
118
+ globals .OutputFormat = strings .ToLower (globals .OutputFormat )
119
+ logFormat = strings .ToLower (logFormat )
120
+
118
121
// should we log to file?
119
122
if logFile != "" {
120
123
file , err := os .OpenFile (logFile , os .O_CREATE | os .O_WRONLY | os .O_APPEND , 0666 )
@@ -124,7 +127,11 @@ func preRun(cmd *cobra.Command, args []string) {
124
127
}
125
128
126
129
// we use a hook so we don't get color codes in the log file
127
- logrus .AddHook (lfshook .NewHook (file , & logrus.TextFormatter {}))
130
+ if logFormat == "json" {
131
+ logrus .AddHook (lfshook .NewHook (file , & logrus.JSONFormatter {}))
132
+ } else {
133
+ logrus .AddHook (lfshook .NewHook (file , & logrus.TextFormatter {}))
134
+ }
128
135
}
129
136
130
137
// should we log to stdout?
@@ -146,19 +153,20 @@ func preRun(cmd *cobra.Command, args []string) {
146
153
logrus .SetLevel (lvl )
147
154
}
148
155
149
- // check the right format was passed
150
- if f , found := parseFormatString (globals .OutputFormat ); ! found {
156
+ // set the Logger format
157
+ if logFormat == "json" {
158
+ logrus .SetFormatter (& logrus.JSONFormatter {})
159
+ }
160
+
161
+ // check the right output format was passed
162
+ format , found := parseFormatString (globals .OutputFormat )
163
+ if ! found {
151
164
feedback .Error ("Invalid output format: " + globals .OutputFormat )
152
165
os .Exit (errorcodes .ErrBadCall )
153
- } else {
154
- // use the format to configure the Feedback
155
- feedback .SetFormat (f )
156
166
}
157
167
158
- // set the Logger format
159
- if strings .ToLower (logFormat ) == "json" {
160
- logrus .SetFormatter (& logrus.JSONFormatter {})
161
- }
168
+ // use the output format to configure the Feedback
169
+ feedback .SetFormat (format )
162
170
163
171
globals .InitConfigs ()
164
172
0 commit comments