Access Logs
By default, logs are written to stdout, in text format.
To enable the access logs:
--accesslog=true
By default access logs are written to the standard output.To write the logs into a log file, use the filePath
option.
By default, logs are written using the Common Log Format (CLF).To write logs in JSON, use json
in the format
option.If the given format is unsupported, the default (CLF) is used instead.
Common Log Format
<remote_IP_address> - <client_user_name_if_available> [<timestamp>] "<request_method> <request_path> <request_protocol>" <origin_server_HTTP_status> <origin_server_content_size> "<request_referrer>" "<request_user_agent>" <number_of_requests_received_since_Traefik_started> "<Traefik_frontend_name>" "<Traefik_backend_URL>" <request_duration_in_ms>ms
# Configuring a buffer of 100 lines
accessLog:
filePath: "/path/to/access.log"
bufferingSize: 100
# Configuring a buffer of 100 lines
--accesslog=true
--accesslog.filepath=/path/to/access.log
--accesslog.bufferingsize=100
To filter logs, you can specify a set of filters which are logically "OR-connected".Thus, specifying multiple filters will keep more access logs than specifying only one.
The available filters are:
statusCodes
, to limit the access logs to requests with a status codes in the specified rangeretryAttempts
, to keep the access logs when at least one retry has happenedminDuration
, to keep access logs when requests take longer than the specified duration
# Configuring Multiple Filters
[accessLog]
format = "json"
[accessLog.filters]
statusCodes = ["200", "300-302"]
retryAttempts = true
minDuration = "10ms"
# Configuring Multiple Filters
--accesslog=true
--accesslog.filepath=/path/to/access.log
--accesslog.format=json
--accesslog.filters.statuscodes=200,300-302
--accesslog.filters.retryattempts
--accesslog.filters.minduration=10ms
Each field can be set to:
keep
to keep the value- to drop the value
redact
to replace the value with "redacted"
The defaultMode
for fields.header
is drop
.
# Limiting the Logs to Specific Fields
[accessLog]
filePath = "/path/to/access.log"
format = "json"
[accessLog.fields]
defaultMode = "keep"
[accessLog.fields.names]
"ClientUsername" = "drop"
[accessLog.fields.headers]
defaultMode = "keep"
[accessLog.fields.headers.names]
"User-Agent" = "redact"
"Authorization" = "drop"
"Content-Type" = "keep"
# Limiting the Logs to Specific Fields
accessLog:
filePath: "/path/to/access.log"
format: json
fields:
defaultMode: keep
names:
ClientUsername: drop
headers:
defaultMode: keep
names:
User-Agent: redact
Authorization: drop
Available Fields
Log Rotation
Traefik will close and reopen its log files, assuming they're configured, on receipt of a USR1 signal.This allows the logs to be rotated and processed by an external program, such as logrotate
.
Warning