From 58b821d9734742d9f050517b1d4d066687cd433e Mon Sep 17 00:00:00 2001 From: ABM Ruman Date: Wed, 25 Mar 2020 04:05:41 +0600 Subject: [PATCH] feat: write logs to file instead of stdout & enable access log --- docker-compose.yml | 21 +++++++++++++++++++++ env.example | 18 ++++++++++++++++++ logs/.gitignore | 2 ++ 3 files changed, 41 insertions(+) create mode 100644 logs/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index bda761b..e43e8a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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: diff --git a/env.example b/env.example index b8927cd..a5bc3fd 100644 --- a/env.example +++ b/env.example @@ -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 diff --git a/logs/.gitignore b/logs/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/logs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore