This commit is contained in:
Giovanni Barbaro 2025-02-17 09:50:31 -08:00 committed by GitHub
commit 5f44ba9fcc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View file

@ -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,7 +53,7 @@ type log struct {
// Config contains the configuration to be used in the Ingress
type Config struct {
Access bool `json:"accessLog"`
Access string `json:"accessLog"`
Rewrite bool `json:"rewriteLog"`
}
@ -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)

View file

@ -1132,7 +1132,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 }}