@@ -19,6 +19,8 @@ const (
19
19
dynamicWeightChangesParam = "weight-changes-dynamic-reload"
20
20
appProtectLogLevelDefault = "fatal"
21
21
appProtectEnforcerAddrDefault = "127.0.0.1:50000"
22
+ logLevelDefault = "info"
23
+ logFormatDefault = "glog"
22
24
)
23
25
24
26
var (
@@ -208,6 +210,11 @@ var (
208
210
209
211
enableTelemetryReporting = flag .Bool ("enable-telemetry-reporting" , true , "Enable gathering and reporting of product related telemetry." )
210
212
213
+ logFormat = flag .String ("log-format" , logFormatDefault , "Set log format to either glog, text, or json." )
214
+
215
+ logLevel = flag .String ("log-level" , logLevelDefault ,
216
+ `Sets log level for Ingress Controller. Allowed values: fatal, error, warning, info, debug, trace.` )
217
+
211
218
enableDynamicWeightChangesReload = flag .Bool (dynamicWeightChangesParam , false , "Enable changing weights of split clients without reloading NGINX. Requires -nginx-plus" )
212
219
213
220
startupCheckFn func () error
@@ -223,6 +230,16 @@ func parseFlags() {
223
230
}
224
231
225
232
func initValidate () {
233
+ logFormatValidationError := validateLogFormat (* logFormat )
234
+ if logFormatValidationError != nil {
235
+ glog .Warningf ("Invalid log format: %s. Valid options are: glog, text, json. Falling back to default: %s" , * logFormat , logFormatDefault )
236
+ }
237
+
238
+ logLevelValidationError := validateLogLevel (* logLevel )
239
+ if logLevelValidationError != nil {
240
+ glog .Warningf ("Invalid log level: %s. Valid options are: trace, debug, info, warning, error, fatal. Falling back to default: %s" , * logLevel , logLevelDefault )
241
+ }
242
+
226
243
if * enableLatencyMetrics && ! * enablePrometheusMetrics {
227
244
glog .Warning ("enable-latency-metrics flag requires enable-prometheus-metrics, latency metrics will not be collected" )
228
245
* enableLatencyMetrics = false
@@ -347,8 +364,8 @@ func mustValidateFlags() {
347
364
}
348
365
349
366
if * appProtectLogLevel != appProtectLogLevelDefault && * appProtect && * nginxPlus {
350
- logLevelValidationError := validateAppProtectLogLevel (* appProtectLogLevel )
351
- if logLevelValidationError != nil {
367
+ appProtectlogLevelValidationError := validateLogLevel (* appProtectLogLevel )
368
+ if appProtectlogLevelValidationError != nil {
352
369
glog .Fatalf ("Invalid value for app-protect-log-level: %v" , * appProtectLogLevel )
353
370
}
354
371
}
@@ -443,8 +460,8 @@ func validatePort(port int) error {
443
460
return nil
444
461
}
445
462
446
- // validateAppProtectLogLevel makes sure a given logLevel is one of the allowed values
447
- func validateAppProtectLogLevel (logLevel string ) error {
463
+ // validateLogLevel makes sure a given logLevel is one of the allowed values
464
+ func validateLogLevel (logLevel string ) error {
448
465
switch strings .ToLower (logLevel ) {
449
466
case
450
467
"fatal" ,
@@ -455,7 +472,16 @@ func validateAppProtectLogLevel(logLevel string) error {
455
472
"trace" :
456
473
return nil
457
474
}
458
- return fmt .Errorf ("invalid App Protect log level: %v" , logLevel )
475
+ return fmt .Errorf ("invalid log level: %v" , logLevel )
476
+ }
477
+
478
+ // validateLogFormat makes sure a given logFormat is one of the allowed values
479
+ func validateLogFormat (logFormat string ) error {
480
+ switch strings .ToLower (logFormat ) {
481
+ case "glog" , "json" , "text" :
482
+ return nil
483
+ }
484
+ return fmt .Errorf ("invalid log format: %v" , logFormat )
459
485
}
460
486
461
487
// parseNginxStatusAllowCIDRs converts a comma separated CIDR/IP address string into an array of CIDR/IP addresses.
0 commit comments