5.2 KiB
Docker Logging Setup - Automatic Configuration
Overview
The Docker setup is automatically configured to use external logback-spring.xml for runtime log level changes. No manual configuration needed!
How It Works
1. Dockerfile Configuration
Both Dockerfile and Dockerfile.inferno automatically:
- Copy
logback-spring.xmlto/app/config/logback-spring.xmlin the container - Create
/app/logsdirectory for log files - Set default environment variables:
LOGGING_CONFIG=/app/config/logback-spring.xmlLOG_DIR=/app/logs
- Configure Java to use external config via
-Dlogging.configand-DLOG_DIR
2. Docker Compose Configuration
Both docker-compose.inferno.yml and docker-compose.prod.yml automatically:
- Mount external config:
/opt/app/backend/config/logback-spring.xml→/app/config/logback-spring.xml(read-write, editable on VPS) - Mount logs directory:
/opt/app/logs→/app/logs(persistent storage) - Set environment variables:
LOGGING_CONFIGandLOG_DIR
Initial Setup (One-Time)
Option 1: Use Setup Script (Recommended)
cd /opt/app/backend
# Make script executable (if not already)
chmod +x scripts/setup-logging.sh
# Run the script
./scripts/setup-logging.sh
This script will:
- Create
/opt/app/backend/configdirectory - Create
/opt/app/logsdirectory - Extract
logback-spring.xmlfrom JAR (if available) - Set proper permissions
Option 2: Manual Setup
# Create directories
mkdir -p /opt/app/backend/config
mkdir -p /opt/app/logs
# Extract logback-spring.xml from JAR
cd /opt/app/backend
unzip -p target/lottery-be-*.jar BOOT-INF/classes/logback-spring.xml > /opt/app/backend/config/logback-spring.xml
# Or copy from source (if building from source on VPS)
cp src/main/resources/logback-spring.xml /opt/app/backend/config/logback-spring.xml
# Set permissions
chmod 644 /opt/app/backend/config/logback-spring.xml
chmod 755 /opt/app/logs
Usage
Start Application
Just start Docker Compose as usual:
cd /opt/app/backend
docker compose -f docker-compose.inferno.yml up -d
The external logging configuration is automatically active - no additional steps needed!
Change Log Level at Runtime
-
Edit the mounted config file:
nano /opt/app/backend/config/logback-spring.xml -
Change log level (example: enable DEBUG):
<logger name="com.lottery" level="DEBUG"/> -
Save the file. Logback will automatically reload within 30 seconds.
-
Verify:
# View logs from VPS tail -f /opt/app/logs/lottery-be.log # Or from inside container docker exec lottery-backend tail -f /app/logs/lottery-be.log
View Logs
# Real-time monitoring
tail -f /opt/app/logs/lottery-be.log
# Search for errors
grep -i "error" /opt/app/logs/lottery-be.log
# View last 100 lines
tail -n 100 /opt/app/logs/lottery-be.log
# From inside container
docker exec lottery-backend tail -f /app/logs/lottery-be.log
File Locations
On VPS (Host)
- Config file:
/opt/app/backend/config/logback-spring.xml(editable) - Log files:
/opt/app/logs/lottery-be.logand rolled files
Inside Container
- Config file:
/app/config/logback-spring.xml(mounted from host) - Log files:
/app/logs/lottery-be.log(mounted to host)
Verification
Check Configuration is Active
# Check container logs for logback initialization
docker logs lottery-backend | grep -i "logback\|logging"
# Check mounted file exists
ls -la /opt/app/backend/config/logback-spring.xml
# Check log directory
ls -la /opt/app/logs/
# Check environment variables in container
docker exec lottery-backend env | grep LOG
Expected Output
You should see:
LOGGING_CONFIG=/app/config/logback-spring.xmlLOG_DIR=/app/logs- Log files appearing in
/opt/app/logs/
Benefits
✅ No manual configuration needed - Works automatically with Docker
✅ Runtime log level changes - Edit file, changes take effect in 30 seconds
✅ No container restart required - Changes apply without restarting
✅ Persistent logs - Logs survive container restarts
✅ Editable config - Edit logback-spring.xml directly on VPS
Troubleshooting
Config file not found
# Check if file exists
ls -la /opt/app/backend/config/logback-spring.xml
# If missing, extract from JAR or copy from source
./scripts/setup-logging.sh
Logs not appearing
# Check log directory permissions
ls -ld /opt/app/logs
# Check container can write
docker exec lottery-backend ls -la /app/logs
# Check disk space
df -h /opt/app/logs
Log level changes not working
- Verify
scan="true" scanPeriod="30 seconds"in logback-spring.xml - Check for XML syntax errors
- Wait 30 seconds after saving
- Check container logs for Logback errors:
docker logs lottery-backend | grep -i "logback\|error"
Summary
You don't need to do anything manually! The Docker setup automatically:
- Uses external logback-spring.xml
- Mounts it as a volume (editable on VPS)
- Sets all required environment variables
- Configures log directory
Just run docker compose up and you're ready to go! 🚀