@@ -19,6 +19,8 @@ const (
1919 dynamicWeightChangesParam = "weight-changes-dynamic-reload"
2020 appProtectLogLevelDefault = "fatal"
2121 appProtectEnforcerAddrDefault = "127.0.0.1:50000"
22+ logLevelDefault = "info"
23+ logFormatDefault = "glog"
2224)
2325
2426var (
@@ -208,6 +210,11 @@ var (
208210
209211 enableTelemetryReporting = flag .Bool ("enable-telemetry-reporting" , true , "Enable gathering and reporting of product related telemetry." )
210212
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+
211218 enableDynamicWeightChangesReload = flag .Bool (dynamicWeightChangesParam , false , "Enable changing weights of split clients without reloading NGINX. Requires -nginx-plus" )
212219
213220 startupCheckFn func () error
@@ -223,6 +230,16 @@ func parseFlags() {
223230}
224231
225232func 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+
226243 if * enableLatencyMetrics && ! * enablePrometheusMetrics {
227244 glog .Warning ("enable-latency-metrics flag requires enable-prometheus-metrics, latency metrics will not be collected" )
228245 * enableLatencyMetrics = false
@@ -347,8 +364,8 @@ func mustValidateFlags() {
347364 }
348365
349366 if * appProtectLogLevel != appProtectLogLevelDefault && * appProtect && * nginxPlus {
350- logLevelValidationError := validateAppProtectLogLevel (* appProtectLogLevel )
351- if logLevelValidationError != nil {
367+ appProtectlogLevelValidationError := validateLogLevel (* appProtectLogLevel )
368+ if appProtectlogLevelValidationError != nil {
352369 glog .Fatalf ("Invalid value for app-protect-log-level: %v" , * appProtectLogLevel )
353370 }
354371 }
@@ -443,8 +460,8 @@ func validatePort(port int) error {
443460 return nil
444461}
445462
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 {
448465 switch strings .ToLower (logLevel ) {
449466 case
450467 "fatal" ,
@@ -455,7 +472,16 @@ func validateAppProtectLogLevel(logLevel string) error {
455472 "trace" :
456473 return nil
457474 }
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 )
459485}
460486
461487// parseNginxStatusAllowCIDRs converts a comma separated CIDR/IP address string into an array of CIDR/IP addresses.
0 commit comments