diff --git a/internal/ingress/annotations/log/main.go b/internal/ingress/annotations/log/main.go index 82d50bac37..ac515e5f3f 100644 --- a/internal/ingress/annotations/log/main.go +++ b/internal/ingress/annotations/log/main.go @@ -32,7 +32,7 @@ var logAnnotations = parser.Annotation{ Group: "log", Annotations: parser.AnnotationFields{ enableAccessLogAnnotation: { - Validator: parser.ValidateBool, + Validator: parser.ValidateOptions([]string{"true", "false", "default"}, true, true), Scope: parser.AnnotationScopeLocation, Risk: parser.AnnotationRiskLow, Documentation: `This configuration setting allows you to control if this location should generate an access_log`, @@ -53,8 +53,8 @@ type log struct { // Config contains the configuration to be used in the Ingress type Config struct { - Access bool `json:"accessLog"` - Rewrite bool `json:"rewriteLog"` + Access string `json:"accessLog"` + Rewrite bool `json:"rewriteLog"` } // Equal tests for equality between two Config types @@ -84,9 +84,9 @@ func (l log) Parse(ing *networking.Ingress) (interface{}, error) { var err error config := &Config{} - config.Access, err = parser.GetBoolAnnotation(enableAccessLogAnnotation, ing, l.annotationConfig.Annotations) + config.Access, err = parser.GetStringAnnotation(enableAccessLogAnnotation, ing, l.annotationConfig.Annotations) if err != nil { - config.Access = true + config.Access = "default" } config.Rewrite, err = parser.GetBoolAnnotation(enableRewriteLogAnnotation, ing, l.annotationConfig.Annotations) diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index f32860dc29..a980287be5 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1127,7 +1127,9 @@ stream { log_by_lua_file /etc/nginx/lua/nginx/ngx_conf_log_block.lua; - {{ if not $location.Logs.Access }} + {{ if $location.Logs.Access == "true" }} + access_log on; + {{ else if $location.Logs.Access == "false" }} access_log off; {{ end }}