Skip to content

Commit

Permalink
feat: write logs to file instead of stdout & enable access log
Browse files Browse the repository at this point in the history
  • Loading branch information
abmruman committed Mar 24, 2020
1 parent b9782cc commit 58b821d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ services:
- --providers.docker.exposedbydefault=false
- --providers.file.filename=/etc/traefik/certs.toml
- --api

# Writing Logs to a file
- --log.filePath=/logs/traefik.log
# supports common (Common Log Format) or json
- --log.format=${LOG_FORMAT:-common}
# Configuring a buffer of 100 lines
- --accesslog=${ACCESSLOG:-true}
- --accesslog.filepath=/logs/access.log
- --accesslog.bufferingsize=${ACCESSLOG_BUFFERINGSIZE:-100}

# access log fields
# Limiting the Logs to Specific Fields
- --accesslog.fields.defaultmode=${ACCESSLOG_FIELDS_DEFAULTMODE:-keep}
- --accesslog.fields.names.ClientUsername=${ACCESSLOG_FIELDS_NAMES_CLIENTUSERNAME:-keep}
- --accesslog.fields.headers.defaultmode=${ACCESSLOG_FIELDS_HEADERS_DEFAULTMODE:-keep}
- --accesslog.fields.headers.names.User-Agent=${ACCESSLOG_FIELDS_HEADERS_NAMES_USER_AGENT:-keep}
- --accesslog.fields.headers.names.Authorization=${ACCESSLOG_FIELDS_HEADERS_NAMES_AUTHORIZATION:-keep}
- --accesslog.fields.headers.names.Content-Type=${ACCESSLOG_FIELDS_HEADERS_NAMES_CONTENT_TYPE:-keep}

# cert resolvers
- --certificatesresolvers.le.acme.caserver=${CA_SERVER}
- --certificatesresolvers.le.acme.email=${EMAIL}
- --certificatesresolvers.le.acme.storage=/acme.json
Expand All @@ -33,6 +53,7 @@ services:
- "${CERT_PATH}:/certs"
- "${ACME_PATH}:/acme.json"
- "${CONFIG_PATH}:/etc/traefik"
- "${LOG_PATH:-./logs}:/logs"
- "${PROVIDER_ENV_FILE_VALUE}:/provider.key:ro"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
labels:
Expand Down
18 changes: 18 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ PROVIDER_ENV_FILE=DO_AUTH_TOKEN_FILE
# (API key must have READ, WRITE access to provider i.e. digitalocean)
# don't forget to `chmod 600` it.
PROVIDER_ENV_FILE_VALUE=./provider.key

# log file path on host machine
LOG_PATH=./logs

# log format
LOG_FORMAT=common

# Access log config
ACCESSLOG=true
ACCESSLOG_BUFFERINGSIZE=100
# access log fields
# Limiting the Logs to Specific Fields
ACCESSLOG_FIELDS_DEFAULTMODE=keep
ACCESSLOG_FIELDS_NAMES_CLIENTUSERNAME=keep
ACCESSLOG_FIELDS_HEADERS_DEFAULTMODE=keep
ACCESSLOG_FIELDS_HEADERS_NAMES_USER_AGENT=keep
ACCESSLOG_FIELDS_HEADERS_NAMES_AUTHORIZATION=keep
ACCESSLOG_FIELDS_HEADERS_NAMES_CONTENT_TYPE=keep
2 changes: 2 additions & 0 deletions logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit 58b821d

Please sign in to comment.