Access Logs

    By default, logs are written to stdout, in text format.

    To enable the access logs:

    1. --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.

    1. <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_router_name>" "<Traefik_server_URL>" <request_duration_in_ms>ms

    To 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.

    1. # Configuring a buffer of 100 lines
    2. accessLog:
    3. filePath: "/path/to/access.log"
    4. bufferingSize: 100
    1. # Configuring a buffer of 100 lines
    2. --accesslog=true
    3. --accesslog.filepath=/path/to/access.log
    4. --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 range
    • retryAttempts, to keep the access logs when at least one retry has happened
    • minDuration, to keep access logs when requests take longer than the specified duration
    1. # Configuring Multiple Filters
    2. [accessLog]
    3. format = "json"
    4. [accessLog.filters]
    5. statusCodes = ["200", "300-302"]
    6. retryAttempts = true
    7. minDuration = "10ms"
    1. # Configuring Multiple Filters
    2. --accesslog=true
    3. --accesslog.filepath=/path/to/access.log
    4. --accesslog.format=json
    5. --accesslog.filters.statuscodes=200,300-302
    6. --accesslog.filters.retryattempts
    7. --accesslog.filters.minduration=10ms

    You can decide to limit the logged fields/headers to a given list with the fields.names and fields.header options

    • keep to keep the value
    • drop to drop the value
    • to replace the value with "redacted"

    The defaultMode for fields.header is drop.

    1. # Limiting the Logs to Specific Fields
    2. [accessLog]
    3. filePath = "/path/to/access.log"
    4. format = "json"
    5. [accessLog.fields]
    6. defaultMode = "keep"
    7. [accessLog.fields.names]
    8. "ClientUsername" = "drop"
    9. [accessLog.fields.headers]
    10. defaultMode = "keep"
    11. [accessLog.fields.headers.names]
    12. "User-Agent" = "redact"
    13. "Authorization" = "drop"
    14. "Content-Type" = "keep"
    1. # Limiting the Logs to Specific Fields
    2. accessLog:
    3. filePath: "/path/to/access.log"
    4. format: json
    5. fields:
    6. defaultMode: keep
    7. names:
    8. ClientUsername: drop
    9. headers:
    10. defaultMode: keep
    11. names:
    12. User-Agent: redact
    13. 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