Logs & AccessLogs

Logs

Logs concern everything that happens to Traefik itself (startup, configuration, events, shutdown, and so on).

Configuration Example

File (YAML)

  1. log:
  2. filePath: "/path/to/log-file.log"
  3. format: json
  4. level: INFO

File (TOML)

  1. [log]
  2. filePath = "/path/to/log-file.log"
  3. format = "json"
  4. level = "INFO"

CLI

  1. --log.filePath=/path/to/log-file.log
  2. --log.format=json
  3. --log.level=INFO

Configuration Options

The section below describe how to configure Traefik logs using the static configuration.

FieldDescriptionDefaultRequired
log.filePathBy default, the logs are written to the standard output.
You can configure a file path instead using the filePath option.
-No
log.formatLog format (commonor json).
The fields displayed with the format common cannot be customized.
“common”No
log.levelLog level (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, and PANIC)ERRORNo
log.noColorWhen using the format common, disables the colorized output.falseNo
log.maxSizeMaximum size in megabytes of the log file before it gets rotated.100MBNo
log.maxAgeMaximum number of days to retain old log files based on the timestamp encoded in their filename.
A day is defined as 24 hours and may not exactly correspond to calendar days due to daylight savings, leap seconds, etc.
By default files are not removed based on their age.
0No
log.maxBackupsMaximum number of old log files to retain.
The default is to retain all old log files.
0No
log.compressCompress log files in gzip after rotation.falseNo

AccessLogs

Configuration Example

File (YAML)

  1. accessLog:
  2. # JSON format
  3. format: json
  4. # Filter on status codes, retry attempts and minimal duration
  5. filters:
  6. statusCodes:
  7. - "200"
  8. - "300-302"
  9. retryAttempts: true
  10. minDuration: "10ms"
  11. fields:
  12. # Keep all the fields by default
  13. defaultMode: keep
  14. names:
  15. # Drop the Field ClientUserName
  16. ClientUsername: drop
  17. headers:
  18. # Keep all the headers by default
  19. defaultMode: keep
  20. names:
  21. # Redact the User-Agent header value
  22. User-Agent: redact
  23. # Drop the Authorization header value
  24. Authorization: drop

File (TOML)

  1. [accessLog]
  2. format = "json"
  3. [accessLog.filters]
  4. statusCodes = [ "200", "300-302" ]
  5. retryAttempts = true
  6. minDuration = "10ms"
  7. [accessLog.fields]
  8. defaultMode = "keep"
  9. [accessLog.fields.names]
  10. ClientUsername = "drop"
  11. [accessLog.fields.headers]
  12. defaultMode = "keep"
  13. [accessLog.fields.headers.names]
  14. User-Agent = "redact"
  15. Authorization = "drop"

CLI

  1. --accesslog=true
  2. --accesslog.format=json
  3. --accesslog.filters.statuscodes=200,300-302
  4. --accesslog.filters.retryattempts
  5. --accesslog.filters.minduration=10ms
  6. --accesslog.fields.defaultmode=keep
  7. --accesslog.fields.names.ClientUsername=drop
  8. --accesslog.fields.headers.defaultmode=keep
  9. --accesslog.fields.headers.names.User-Agent=redact
  10. --accesslog.fields.headers.names.Authorization=drop

Configuration Options

The section below describes how to configure Traefik access logs using the static configuration.

FieldDescriptionDefaultRequired
accesslog.filePathBy default, the access logs are written to the standard output.
You can configure a file path instead using the filePath option.
No
accesslog.formatBy 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.
More information about CLF fields here.
“common”No
accesslog.bufferingSizeTo write the logs in an asynchronous fashion, specify a bufferingSize option.
This option represents the number of log lines Traefik will keep in memory before writing them to the selected output.
In some cases, this option can greatly help performances.
0No
accesslog.addInternalsEnables access logs for internal resources (e.g.: ping@internal).falseNo
accesslog.filters.statusCodesLimit the access logs to requests with a status codes in the specified range.falseNo
accesslog.filters.retryAttemptsKeep the access logs when at least one retry has happened.falseNo
accesslog.filters.minDurationKeep access logs when requests take longer than the specified duration (provided in seconds or as a valid duration format, see time.ParseDuration).0No
accesslog.fields.defaultModeMode to apply by default to the access logs fields (keep, redact or drop).keepNo
accesslog.fields.namesSet the fields list to display in the access logs (format name:mode).
Available fields list here.
-No
accesslog.headers.defaultModeMode to apply by default to the access logs headers (keep, redact or drop).dropNo
accesslog.headers.namesSet the headers list to display in the access logs (format name:mode).-No

CLF format fields

Below the fields displayed with the CLF format:

  1. <remote_IP_address> - <client_user_name_if_available> [<timestamp>]
  2. "<request_method> <request_path> <request_protocol>" <HTTP_status> <content-length>
  3. "<request_referrer>" "<request_user_agent>" <number_of_requests_received_since_Traefik_started>
  4. "<Traefik_router_name>" "<Traefik_server_URL>" <request_duration_in_ms>ms

Available Fields

FieldDescription
StartUTCThe time at which request processing started.
StartLocalThe local time at which request processing started.
DurationThe total time taken (in nanoseconds) by processing the response, including the origin server’s time but not the log writing time.
RouterNameThe name of the Traefik router.
ServiceNameThe name of the Traefik backend.
ServiceURLThe URL of the Traefik backend.
ServiceAddrThe IP:port of the Traefik backend (extracted from ServiceURL).
ClientAddrThe remote address in its original form (usually IP:port).
ClientHostThe remote IP address from which the client request was received.
ClientPortThe remote TCP port from which the client request was received.
ClientUsernameThe username provided in the URL, if present.
RequestAddrThe HTTP Host header (usually IP:port). This is treated as not a header by the Go API.
RequestHostThe HTTP Host server name (not including port).
RequestPortThe TCP port from the HTTP Host.
RequestMethodThe HTTP method.
RequestPathThe HTTP request URI, not including the scheme, host or port.
RequestProtocolThe version of HTTP requested.
RequestSchemeThe HTTP scheme requested http or https.
RequestLineThe RequestMethod, + RequestPath and RequestProtocol.
RequestContentSizeThe number of bytes in the request entity (a.k.a. body) sent by the client.
OriginDurationThe time taken (in nanoseconds) by the origin server (‘upstream’) to return its response.
OriginContentSizeThe content length specified by the origin server, or 0 if unspecified.
OriginStatusThe HTTP status code returned by the origin server. If the request was handled by this Traefik instance (e.g. with a redirect), then this value will be absent (0).
OriginStatusLineOriginStatus + Status code explanation
DownstreamStatusThe HTTP status code returned to the client.
DownstreamStatusLineThe DownstreamStatus and status code explanation.
DownstreamContentSizeThe number of bytes in the response entity returned to the client. This is in addition to the “Content-Length” header, which may be present in the origin response.
RequestCountThe number of requests received since the Traefik instance started.
GzipRatioThe response body compression ratio achieved.
OverheadThe processing time overhead (in nanoseconds) caused by Traefik.
RetryAttemptsThe amount of attempts the request was retried.
TLSVersionThe TLS version used by the connection (e.g. 1.2) (if connection is TLS).
TLSCipherThe TLS cipher used by the connection (e.g. TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA) (if connection is TLS).
TLSClientSubjectThe string representation of the TLS client certificate’s Subject (e.g. CN=username,O=organization).

Log Rotation

Traefik 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

This does not work on Windows due to the lack of USR signals.

Time Zones

Traefik will timestamp each log line in UTC time by default.

It is possible to configure the Traefik to timestamp in a specific timezone by ensuring the following configuration has been made in your environment:

  1. Provide time zone data to /etc/localtime or /usr/share/zoneinfo (based on your distribution) or set the environment variable TZ to the desired timezone.
  2. Specify the field StartLocal by dropping the field named StartUTC (available on the default Common Log Format (CLF) as well as JSON): accesslog.fields.names.StartUTC=drop.

Example utilizing Docker Compose:

  1. version: "3.7"
  2. services:
  3. traefik:
  4. image: traefik:v3.2
  5. environment:
  6. - TZ=US/Alaska
  7. command:
  8. - --accesslog.fields.names.StartUTC=drop
  9. - --providers.docker
  10. ports:
  11. - 80:80
  12. volumes:
  13. - /var/run/docker.sock:/var/run/docker.sock

Using Traefik OSS in Production?

If you are using Traefik at work, consider adding enterprise-grade API gateway capabilities or commercial support for Traefik OSS.

Adding API Gateway capabilities to Traefik OSS is fast and seamless. There’s no rip and replace and all configurations remain intact. See it in action via this short video.