Logging Config#

You can modify the logging configuration through .env` settings files.

All environments share the same logging file ENV Variable Name.

Sharing a common ENV Variable Name keeps configuration simplifies changing the logging file name for each environment.

Rotating Log Files#

django-cookiecutter uses Rotating Logs to prevent log file size from growing too large. The default settings, see below, are located in config/settings/base.py.

The backupCount setting allows up to five log files before it starts removing them.

The maxBytes setting is the maximum size a file can be before it is closed and rotated to a new file.

 1"rotated_logs": {
 2    "class": "logging.handlers.RotatingFileHandler",
 3    "filename": DJANGO_LOG_FILE,
 4    "level": DJANGO_LOGGING_LEVEL,
 5    "mode": "a",
 6    "encoding": "utf-8",
 7    "formatter": "verbose",
 8    "backupCount": 5,
 9    "maxBytes": 10485760,
10},

Local and Test#

Local and Test environments also share the same logging level ENV Variable name.

See the local environment configuration file below.

1 my-django-project
2     └── .env
3         ├── .local
4         ├── .production
5         ├── .staging
6         └── .testing
 1ALLOWED_HOSTS=localhost,0.0.0.0,127.0.0.1
 2DJANGO_DEBUG=True
 3DJANGO_LOG_FILE="logging/rotating_local.log"
 4DJANGO_LOGGING_LEVEL="DEBUG"
 5DJANGO_LOGGING_MAIL_ADMINS="ERROR"
 6DJANGO_MANAGEPY_MIGRATE=on
 7DJANGO_SECRET_KEY="!!!INSECURE_PRODUCTION_SECRET!!!"
 8DJANGO_SETTINGS_MODULE=config.settings.local
 9EMAIL_BACKEND="django.core.mail.backends.console.EmailBackend"
10INTERNAL_IPS=127.0.0.1,10.0.2.2
11DB_ENGINE=""
12DB_NAME=""
13DB_USER=""
14DB_PASSWORD=""
15DB_HOST=""
16DB_PORT=""

Staging and Production#

Staging and Production environments add the environment suffix to the ENV Variable to differentiate between the two environments.

See the production file below, showing the addition of the _PRODUCTION suffix, and specifying the production logging file location.

1 my-django-project
2     └── .env
3         ├── .local
4         ├── .production
5         ├── .staging
6         └── .testing
 1DJANGO_DEBUG=FALSE
 2DJANGO_LOG_FILE="logging/rotating_production.log"
 3DJANGO_LOGGING_LEVEL_PRODUCTION="INFO"
 4DJANGO_LOGGING_MAIL_ADMINS="ERROR"
 5DJANGO_MANAGEPY_MIGRATE=on
 6DJANGO_SECRET_KEY=""
 7DJANGO_SETTINGS_MODULE=config.settings.production
 8DB_ENGINE=""
 9DB_NAME=""
10DB_USER=""
11DB_PASSWORD=""
12DB_HOST=""
13DB_PORT=""
14INTERNAL_IPS=""

Email Admins#

By default, Sending emails to admins is set to ERROR for all environments.

You can change what logging level the Admins will receive an email with the email admins variable; see below.

 1DJANGO_DEBUG=FALSE
 2DJANGO_LOG_FILE="logging/rotating_production.log"
 3DJANGO_LOGGING_LEVEL_PRODUCTION="INFO"
 4DJANGO_LOGGING_MAIL_ADMINS="ERROR"
 5DJANGO_MANAGEPY_MIGRATE=on
 6DJANGO_SECRET_KEY=""
 7DJANGO_SETTINGS_MODULE=config.settings.production
 8DB_ENGINE=""
 9DB_NAME=""
10DB_USER=""
11DB_PASSWORD=""
12DB_HOST=""
13DB_PORT=""
14INTERNAL_IPS=""