Log UWSGI if debug is set (DISPATCHARR_DEBUG=true)

This commit is contained in:
SergeantPanda 2025-05-14 18:49:46 -05:00
parent 14c3944578
commit 44a79d2a8a
4 changed files with 52 additions and 16 deletions

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -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