From 2c277d13f631b9c7815e25e6d3c963895132e8d0 Mon Sep 17 00:00:00 2001 From: Django Template Date: Thu, 11 Sep 2025 16:19:38 +0530 Subject: [PATCH] Fix Django logging configuration for Docker containers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- DOKPLOY.md | 16 +++++++++++++++- django_project/settings/production.py | 18 +++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/DOKPLOY.md b/DOKPLOY.md index 2d10930..d62e3f3 100644 --- a/DOKPLOY.md +++ b/DOKPLOY.md @@ -33,7 +33,16 @@ TTL: 3600 1. **Inside your project**, click **"Create Service"** 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 @@ -236,6 +245,11 @@ python manage.py collectstatic --noinput # - 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** ```bash # Check DNS propagation diff --git a/django_project/settings/production.py b/django_project/settings/production.py index d3db806..71f7164 100644 --- a/django_project/settings/production.py +++ b/django_project/settings/production.py @@ -30,14 +30,12 @@ LOGGING = { 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}', 'style': '{', }, + 'simple': { + 'format': '{levelname} {message}', + 'style': '{', + }, }, 'handlers': { - 'file': { - 'level': 'INFO', - 'class': 'logging.FileHandler', - 'filename': '/var/log/django/django.log', - 'formatter': 'verbose', - }, 'console': { 'level': 'INFO', 'class': 'logging.StreamHandler', @@ -46,12 +44,18 @@ LOGGING = { }, 'root': { 'handlers': ['console'], + 'level': 'INFO', }, 'loggers': { 'django': { - 'handlers': ['file', 'console'], + 'handlers': ['console'], 'level': 'INFO', 'propagate': False, }, + 'django.request': { + 'handlers': ['console'], + 'level': 'ERROR', + 'propagate': False, + }, }, } \ No newline at end of file