Skip to content

Commit

Permalink
feat: Enhance logging configuration and ensure logs directory creatio…
Browse files Browse the repository at this point in the history
…n; update render.yaml for improved deployment
  • Loading branch information
AhmedNassar7 committed Dec 18, 2024
1 parent d7084f0 commit 6b19013
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
32 changes: 18 additions & 14 deletions egypt_metro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,36 +204,40 @@
"REFRESH_TOKEN_LIFETIME": timedelta(days=7), # Refresh token lifetime
}

# Create logs directory if it doesn't exist
LOGS_DIR = BASE_DIR / "logs"
LOGS_DIR.mkdir(exist_ok=True)

LOGGING = {
"version": 1, # Log version
"disable_existing_loggers": False, # Don't disable existing loggers
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": "{levelname} {asctime} {module} {message}", # Log format
"style": "{", # Use {} for formatting
"format": "{levelname} {asctime} {module} {message}",
"style": "{",
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler", # Log to console
"formatter": "verbose", # Use the verbose formatter
"class": "logging.StreamHandler",
"formatter": "verbose",
},
"file": {
"level": "DEBUG", # Log debug messages
"class": "logging.FileHandler", # Log to file
"filename": BASE_DIR / "logs/debug.log", # File where logs are saved
"formatter": "verbose", # Use the verbose formatter
"level": "DEBUG",
"class": "logging.FileHandler",
"filename": str(LOGS_DIR / "debug.log"),
"formatter": "verbose",
},
},
"loggers": {
"django": {
"handlers": ["console", "file"], # Log to console and file
"level": "INFO", # Log info messages
"handlers": ["console"], # Only console for production
"level": "INFO",
"propagate": True,
},
"__main__": {
"handlers": ["console", "file"], # Log to console and file
"level": "DEBUG", # Log all messages
"handlers": ["console"], # Only console for production
"level": "DEBUG",
"propagate": True,
},
},
Expand Down
18 changes: 10 additions & 8 deletions render.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# render.yaml

# Render configuration file for deploying a Django application to Render
# https://render.com/docs/deploy-django

services:
- type: web
name: django
runtime: python
dockerfilePath: ./Dockerfile
buildCommand: >
apt-get update && apt-get install -y gcc libpq-dev python3-dev &&
pip install --upgrade pip &&
pip install poetry &&
poetry install --no-dev &&
python manage.py collectstatic --noinput &&
buildCommand: |
apt-get update && apt-get install -y gcc libpq-dev python3-dev && \
pip install --upgrade pip && \
pip install poetry && \
poetry install --no-dev && \
python manage.py collectstatic --noinput && \
python manage.py migrate --noinput
startCommand: "gunicorn egypt_metro.wsgi:application --bind 0.0.0.0:8000 --workers=3 --threads=2 --timeout=120"
startCommand: gunicorn egypt_metro.wsgi:application --bind 0.0.0.0:$PORT --workers=3 --threads=2 --timeout=120
envVars:
- key: ENVIRONMENT # Environment for loading specific config
value: prod
Expand All @@ -32,3 +33,4 @@ services:
mountPath: /var/lib/egypt-metro
sizeGB: 1
healthCheckPath: "/health" # Optional, ensure health endpoint exists
autoDeploy: true # Optional, auto-deploy when code is pushed to Git

0 comments on commit 6b19013

Please sign in to comment.