From 44a79d2a8a85a8b9c68f1836d9683af3ee164582 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Wed, 14 May 2025 18:49:46 -0500 Subject: [PATCH] Log UWSGI if debug is set (DISPATCHARR_DEBUG=true) --- docker/entrypoint.sh | 26 ++++++++++++++++++-------- docker/uwsgi.debug.ini | 12 ++++++++---- docker/uwsgi.dev.ini | 15 +++++++++++++-- docker/uwsgi.ini | 15 +++++++++++++-- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 7913ae47..2d9f7fdc 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -53,11 +53,14 @@ if [ -n "$DISPATCHARR_TIMESTAMP" ]; then else echo "📦 Dispatcharr version: ${DISPATCHARR_VERSION}" fi - +export DISPATCHARR_LOG_LEVEL # Set log level with default if not provided -export DISPATCHARR_LOG_LEVEL=${DISPATCHARR_LOG_LEVEL:-info} -echo "Environment DISPATCHARR_LOG_LEVEL detected as: '${DISPATCHARR_LOG_LEVEL}'" -echo "Setting log level to: ${DISPATCHARR_LOG_LEVEL}" +DISPATCHARR_LOG_LEVEL=${DISPATCHARR_LOG_LEVEL:-INFO} +# Convert to uppercase +DISPATCHARR_LOG_LEVEL=${DISPATCHARR_LOG_LEVEL^^} + + +echo "Environment DISPATCHARR_LOG_LEVEL set to: '${DISPATCHARR_LOG_LEVEL}'" # Also make the log level available in /etc/environment for all login shells #grep -q "DISPATCHARR_LOG_LEVEL" /etc/environment || echo "DISPATCHARR_LOG_LEVEL=${DISPATCHARR_LOG_LEVEL}" >> /etc/environment @@ -143,10 +146,17 @@ else uwsgi_file="/app/docker/uwsgi.ini" fi -# Pass all environment variables to the uwsgi process -# The -p/--preserve-environment flag ensures all environment variables are passed through -su -p - $POSTGRES_USER -c "cd /app && uwsgi --ini $uwsgi_file &" -uwsgi_pid=$(pgrep uwsgi | sort | head -n1) +# Set base uwsgi args +uwsgi_args="--ini $uwsgi_file" + +# Conditionally disable logging if not in debug mode +if [ "$DISPATCHARR_DEBUG" != "true" ]; then + uwsgi_args+=" --disable-logging" +fi + +# Launch uwsgi -p passes environment variables to the process +su -p - $POSTGRES_USER -c "cd /app && uwsgi $uwsgi_args &" +uwsgi_pid=$(pgrep uwsgi | sort | head -n1) echo "✅ uwsgi started with PID $uwsgi_pid" pids+=("$uwsgi_pid") diff --git a/docker/uwsgi.debug.ini b/docker/uwsgi.debug.ini index 9cd4ccdf..43ecd5ce 100644 --- a/docker/uwsgi.debug.ini +++ b/docker/uwsgi.debug.ini @@ -19,6 +19,7 @@ module = scripts.debug_wrapper:application virtualenv = /dispatcharrpy master = true env = DJANGO_SETTINGS_MODULE=dispatcharr.settings + socket = /app/uwsgi.sock chmod-socket = 777 vacuum = true @@ -58,9 +59,6 @@ ignore-sigpipe = true ignore-write-errors = true disable-write-exception = true -# Explicitly disable for-server option that confuses debugpy -for-server = false - # Debugging settings py-autoreload = 1 honour-stdin = true @@ -78,4 +76,10 @@ env = DEBUGPY_LOG_DIR=/app/debugpy_logs env = WAIT_FOR_DEBUGGER=false env = DEBUG_TIMEOUT=30 - +# Enable console logging (stdout) +log-master = true +# Enable strftime formatting for timestamps +logformat-strftime = true +log-date = %%Y-%%m-%%d %%H:%%M:%%S,000 +# Use the environment variable in log format - ensure consistent formatting with other files +log-format = %(ftime) $(DISPATCHARR_LOG_LEVEL) uwsgi.requests Worker ID: %(wid) %(method) %(status) %(uri) %(msecs)ms \ No newline at end of file diff --git a/docker/uwsgi.dev.ini b/docker/uwsgi.dev.ini index 455111d3..62a5f352 100644 --- a/docker/uwsgi.dev.ini +++ b/docker/uwsgi.dev.ini @@ -1,6 +1,8 @@ [uwsgi] -; exec-before = python manage.py collectstatic --noinput -; exec-before = python manage.py migrate --noinput +; Remove file creation commands since we're not logging to files anymore +; exec-pre = mkdir -p /data/logs +; exec-pre = touch /data/logs/uwsgi-dev.log +; exec-pre = chmod 666 /data/logs/uwsgi-dev.log ; First run Redis availability check script once exec-pre = python /app/scripts/wait_for_redis.py @@ -47,3 +49,12 @@ thunder-lock = true log-4xx = true log-5xx = true disable-logging = false + +# Logging configuration - development mode +# Enable console logging (stdout) +log-master = true +# Enable strftime formatting for timestamps +logformat-strftime = true +log-date = %%Y-%%m-%%d %%H:%%M:%%S,000 +# Use formatted time with environment variable for log level +log-format = %(ftime) $(DISPATCHARR_LOG_LEVEL) uwsgi.requests Worker ID: %(wid) %(method) %(status) %(uri) %(msecs)ms \ No newline at end of file diff --git a/docker/uwsgi.ini b/docker/uwsgi.ini index 75d4de3f..5068268c 100644 --- a/docker/uwsgi.ini +++ b/docker/uwsgi.ini @@ -1,6 +1,8 @@ [uwsgi] -; exec-before = python manage.py collectstatic --noinput -; exec-before = python manage.py migrate --noinput +; Remove file creation commands since we're not logging to files anymore +; exec-pre = mkdir -p /data/logs +; exec-pre = touch /data/logs/uwsgi.log +; exec-pre = chmod 666 /data/logs/uwsgi.log ; First run Redis availability check script once exec-pre = python /app/scripts/wait_for_redis.py @@ -45,3 +47,12 @@ thunder-lock = true log-4xx = true log-5xx = true disable-logging = false + +# Logging configuration +# Enable console logging (stdout) +log-master = true +# Enable strftime formatting for timestamps +logformat-strftime = true +log-date = %%Y-%%m-%%d %%H:%%M:%%S,000 +# Use formatted time with environment variable for log level +log-format = %(ftime) $(DISPATCHARR_LOG_LEVEL) uwsgi.requests Worker ID: %(wid) %(method) %(status) %(uri) %(msecs)ms \ No newline at end of file