Fix Django logging configuration for Docker containers

## Issue Fixed:
- Django production logging was trying to write to `/var/log/django/django.log`
- This directory doesn't exist in Docker containers, causing deployment failures
- Error: `FileNotFoundError: [Errno 2] No such file or directory: '/var/log/django/django.log'`

## Solution:
- **Modified production.py**: Switched from file-based to console-only logging
- **Docker-friendly logging**: All logs now go to stdout/stderr for container compatibility
- **Dokploy integration**: Logs are now visible in Dokploy's log viewer
- **Added troubleshooting**: Updated DOKPLOY.md with this specific error and solution

## Benefits:
-  Works seamlessly with Docker containers
-  Integrates with Dokploy log viewing system
-  No file permissions or directory creation issues
-  Standard practice for containerized applications

This fixes the deployment failure identified in the Dokploy logs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Django Template 2025-09-11 16:19:38 +05:30
parent 07dd7b0e47
commit 2c277d13f6
2 changed files with 26 additions and 8 deletions

View File

@ -33,7 +33,16 @@ TTL: 3600
1. **Inside your project**, click **"Create Service"** 1. **Inside your project**, click **"Create Service"**
2. **Select Service Type**: **"Compose"** 2. **Select Service Type**: **"Compose"**
3. **Choose Compose Type**: **"Docker Compose"** (not Stack) 3. **Fill the "Create Compose" form**:
### 📝 Form Fields to Fill:
- **Name**: `Django Template` *(or your preferred service name)*
- **App Name**: `django-template-prod` *(unique identifier for this service)*
- **Compose Type**: `Docker Compose` *(keep as selected)*
- **Description**: `Modern Django template with Tailwind CSS, authentication, and PostgreSQL database`
4. **Click "Create"** to proceed to configuration
## 📂 Step 4: Configure Repository Source ## 📂 Step 4: Configure Repository Source
@ -236,6 +245,11 @@ python manage.py collectstatic --noinput
# - Network connectivity issues # - Network connectivity issues
``` ```
### **Django Logging Error (FileNotFoundError)**
If you see error: `FileNotFoundError: [Errno 2] No such file or directory: '/var/log/django/django.log'`
**Solution**: This is already fixed in the latest version. The production settings now use console logging only, which is Docker-friendly and works with Dokploy's log viewing system.
### **Domain Not Accessible** ### **Domain Not Accessible**
```bash ```bash
# Check DNS propagation # Check DNS propagation

View File

@ -30,14 +30,12 @@ LOGGING = {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}', 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{', 'style': '{',
}, },
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
}, },
'handlers': { 'handlers': {
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': '/var/log/django/django.log',
'formatter': 'verbose',
},
'console': { 'console': {
'level': 'INFO', 'level': 'INFO',
'class': 'logging.StreamHandler', 'class': 'logging.StreamHandler',
@ -46,12 +44,18 @@ LOGGING = {
}, },
'root': { 'root': {
'handlers': ['console'], 'handlers': ['console'],
'level': 'INFO',
}, },
'loggers': { 'loggers': {
'django': { 'django': {
'handlers': ['file', 'console'], 'handlers': ['console'],
'level': 'INFO', 'level': 'INFO',
'propagate': False, 'propagate': False,
}, },
'django.request': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
}, },
} }