Implement additional log format: json access logs

This commit is contained in:
sfinke0 2023-02-24 09:46:49 +01:00
parent a45516468d
commit b2a30145cb
5 changed files with 7 additions and 4 deletions

View file

@ -18,7 +18,8 @@ ENV GENERICCACHE_VERSION=2 \
LOGFILE_RETENTION=3560 \
CACHE_DOMAINS_REPO="https://github.com/uklans/cache-domains.git" \
CACHE_DOMAINS_BRANCH=master \
NGINX_WORKER_PROCESSES=auto
NGINX_WORKER_PROCESSES=auto \
NGINX_LOG_FORMAT=cachelog
COPY overlay/ /

View file

@ -1,2 +1,2 @@
log_format cachelog '[$cacheidentifier] $remote_addr / $http_x_forwarded_for - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$upstream_cache_status" "$host" "$http_range"';
log_format cachelog-json escape=json '{"timestamp":"$msec","time_local":"$time_local","cache_identifier":"$cacheidentifier","remote_addr":"$remote_addr","forwarded_for":"$http_x_forwarded_for","remote_user":"$remote_user","status":"$status","bytes_sent":$body_bytes_sent,"referer":"$http_referer","user_agent":"$http_user_agent","upstream_cache_status":"$upstream_cache_status","host":"$host","http_range":"$http_range","method":"$request_method","path":"$request_uri","proto":"$server_protocol","scheme":"$scheme"}';

View file

@ -3,7 +3,7 @@
server {
listen 80 reuseport;
access_log /data/logs/access.log cachelog;
access_log /data/logs/access.log LOG_FORMAT;
error_log /data/logs/error.log;
include /etc/nginx/sites-available/cache.conf.d/*.conf;

View file

@ -10,7 +10,7 @@ server {
# No access_log tracking as all requests to this instance are already logged through monolithic
# access_log /data/logs/upstream-access.log cachelog;
# access_log /data/logs/upstream-access.log LOG_FORMAT;
error_log /data/logs/upstream-error.log;
include /etc/nginx/sites-available/upstream.conf.d/*.conf;

View file

@ -19,3 +19,5 @@ sed -i "s/slice 1m;/slice ${CACHE_SLICE_SIZE};/" /etc/nginx/sites-available/cach
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/cache.conf.d/10_root.conf
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf.d/10_resolver.conf
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf
sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/10_cache.conf
sed -i "s/LOG_FORMAT/${NGINX_LOG_FORMAT}/" /etc/nginx/sites-available/20_upstream.conf