Skip to content

Commit

Permalink
feat: handle log filePath and noColor
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweaver87 authored Jul 11, 2024
1 parent d613258 commit 51fc564
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 27 deletions.
64 changes: 38 additions & 26 deletions traefik/templates/_podtemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -621,46 +621,58 @@
{{- end }}
{{- end }}
{{- with .Values.logs }}
{{- if .general.format }}
{{- if and .general.format (not (has .general.format (list "common" "json"))) }}
{{- fail "ERROR: .Values.logs.general.format must be either common or json" }}
{{- end }}
{{- if .general.format }}
- "--log.format={{ .general.format }}"
{{- end }}
{{- if ne .general.level "ERROR" }}
{{- end }}
{{- if .general.filePath }}
- "--log.filePath={{ .general.filePath }}"
{{- end }}
{{- if and (or (eq .general.format "common") (not .general.format)) (eq .general.noColor true) }}
- "--log.noColor={{ .general.noColor }}"
{{- end }}
{{- if and .general.level (not (has (.general.level | upper) (list "DEBUG" "PANIC" "FATAL" "ERROR" "WARN" "INFO"))) }}
{{- fail "ERROR: .Values.logs.level must be DEBUG, PANIC, FATAL, ERROR, WARN, and INFO" }}
{{- end }}
{{- if .general.level }}
- "--log.level={{ .general.level | upper }}"
{{- end }}
{{- if .access.enabled }}
{{- end }}
{{- if .access.enabled }}
- "--accesslog=true"
{{- with .access.format }}
{{- with .access.format }}
- "--accesslog.format={{ . }}"
{{- end }}
{{- with .access.filePath }}
{{- end }}
{{- with .access.filePath }}
- "--accesslog.filepath={{ . }}"
{{- end }}
{{- if .access.addInternals }}
{{- end }}
{{- if .access.addInternals }}
- "--accesslog.addinternals"
{{- end }}
{{- with .access.bufferingSize }}
{{- end }}
{{- with .access.bufferingSize }}
- "--accesslog.bufferingsize={{ . }}"
{{- end }}
{{- with .access.filters }}
{{- with .statuscodes }}
{{- end }}
{{- with .access.filters }}
{{- with .statuscodes }}
- "--accesslog.filters.statuscodes={{ . }}"
{{- end }}
{{- if .retryattempts }}
{{- end }}
{{- if .retryattempts }}
- "--accesslog.filters.retryattempts"
{{- end }}
{{- with .minduration }}
{{- end }}
{{- with .minduration }}
- "--accesslog.filters.minduration={{ . }}"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
- "--accesslog.fields.defaultmode={{ .access.fields.general.defaultmode }}"
{{- range $fieldname, $fieldaction := .access.fields.general.names }}
{{- range $fieldname, $fieldaction := .access.fields.general.names }}
- "--accesslog.fields.names.{{ $fieldname }}={{ $fieldaction }}"
{{- end }}
{{- end }}
- "--accesslog.fields.headers.defaultmode={{ .access.fields.headers.defaultmode }}"
{{- range $fieldname, $fieldaction := .access.fields.headers.names }}
{{- range $fieldname, $fieldaction := .access.fields.headers.names }}
- "--accesslog.fields.headers.names.{{ $fieldname }}={{ $fieldaction }}"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- range $resolver, $config := $.Values.certResolvers }}
{{- range $option, $setting := $config }}
Expand Down
53 changes: 53 additions & 0 deletions traefik/tests/pod-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,56 @@ tests:
- notContains:
path: spec.template.spec.containers[0].args
content: "--core.defaultRuleSyntax=v2"
- it: should fail when providing bad log format
set:
logs:
general:
format: "test"
asserts:
- failedTemplate:
errorMessage: "ERROR: .Values.logs.general.format must be either common or json"
- it: should set log filePath when configured
set:
logs:
general:
filePath: "/var/log/traefik.log"
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: "--log.filePath=/var/log/traefik.log"
- it: should set log noColor when configured
set:
logs:
general:
noColor: true
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: "--log.noColor=true"
- it: should set log noColor when configured to false as it's default
set:
logs:
general:
noColor: false
asserts:
- notContains:
path: spec.template.spec.containers[0].args
content: "--log.noColor=false"
- it: should not set log noColor when configured and log format is not common
set:
logs:
general:
format: json
noColor: true
asserts:
- notContains:
path: spec.template.spec.containers[0].args
content: "--log.noColor=true"
- it: should fail when setting unknown log level
set:
logs:
general:
level: test
asserts:
- failedTemplate:
errorMessage: "ERROR: .Values.logs.level must be DEBUG, PANIC, FATAL, ERROR, WARN, and INFO"
5 changes: 4 additions & 1 deletion traefik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,12 @@ logs:
# -- Set [logs format](https://doc.traefik.io/traefik/observability/logs/#format)
# @default common
format:
# By default, the level is set to ERROR.
# By default, the level is set to INFO.
# -- Alternative logging levels are DEBUG, PANIC, FATAL, ERROR, WARN, and INFO.
level: INFO
#
# filePath: "/var/log/traefik/traefik.log
# noColor: true
access:
# -- To enable access logs
enabled: false
Expand Down

0 comments on commit 51fc564

Please sign in to comment.