Commit 8b83919a authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add [better] timestamps to log output

Generally improve logging with some consistently formatted timestamps
and clearer access log formats.
parent ea06c575
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ RUN --mount=type=bind,source=scripts/install-wp.sh,target=/stage \
    /stage ${wp_version}

COPY probe.php wp-content/mu-plugins/
COPY fpm.conf /usr/local/etc/php-fpm.d/image.conf
COPY opcache.ini /usr/local/etc/php/conf.d/opcache-recommended.ini
COPY wp-config.php /usr/share/wordpress/wp-config.php
COPY entrypoint.sh /bin/entrypoint
+8 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ declare -a WP_CONFIGS=(
)


timestamp()
{
	echo "[$(date --utc +'%Y-%m-%dT%H:%M:%S%z')] $*"
}

create_config()
{
	[[ -f wp-config.php ]] && unlink wp-config.php
@@ -158,6 +163,7 @@ run_cron()
	enable -f /usr/lib/bash/head head
	while wp cron event run --due-now || true; do
		sleep $(next_cron)
		timestamp "Executing cron tasks"
	done
}

@@ -192,10 +198,12 @@ case "$1" in
	collect-static) create_config && setup_components && collect_static ;;
	run-cron) create_config && run_cron ;;
	php-fpm)
		timestamp "Starting Wordpress preparation"
		create_config
		setup_components
		setup_media
		collect_static
		timestamp "Completed Wordpress preparation"
		run_background_cron
		exec "$@" "${extra_args[@]}"
		;;

fpm.conf

0 → 100644
+1 −0
Original line number Diff line number Diff line
access.format = "[%{%Y-%m-%dT%H:%M:%S%z}t] %{REMOTE_ADDR}e %m %{REQUEST_URI}e%Q%q %s time=%{mili}d ms;"
+7 −0
Original line number Diff line number Diff line
@@ -3,10 +3,17 @@ map $http_x_forwarded_proto $forwarded_https {
	https on;
}

log_format clear '[$time_iso8601] $remote_addr '
                 '$request_method $request_uri$is_args$args $status '
				 ' sent=$body_bytes_sent bytes;'
				 ' referrer=$http_referer;'
				 ' user-agent=$http_user_agent';

server {
	listen 80;
	server_name _;
	root /app/static;
	access_log /dev/stdout clear;

	# Consider all private IP addresses safe sources for X-Forwarded-For
	set_real_ip_from 10.0.0.0/8;