Logging Config#
You can modify the logging configuration through .env`
settings files.
All environments share the same logging file ENV Variable Name with a prefix.
For example DJANGO_LOGGING_LEVEL
for the local environment would be
LOCAL_DJANGO_LOGGING_LEVEL
Sharing a common ENV Variable Name with a prefix allows greater control over logging.
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#
See the local environment configuration file below.
1 my-django-project
2 └── .env
3 ├── .local
4 ├── .production
5 ├── .staging
6 └── .testing
1# Local Environment ENV Keys
2
3# Local Environment Django
4LOCAL_ALLOWED_HOSTS=localhost,0.0.0.0,127.0.0.1,testserver
5# Local database options: sqlite3, other.
6# If using other, a LOCAL_DATABASE_URL connection string must be supplied.
7LOCAL_DJANGO_DATABASE=sqlite3
8LOCAL_DATABASE_URL=""
9LOCAL_DJANGO_DEBUG=True
10LOCAL_DJANGO_INTERNAL_IPS=127.0.0.1,10.0.2.2
11LOCAL_DJANGO_LOG_FILE='logging/rotating.log'
12LOCAL_DJANGO_LOGGING_LEVEL='DEBUG'
13LOCAL_DJANGO_LOGGING_MAIL_ADMINS='ERROR'
14# For the docker image
15LOCAL_DJANGO_MANAGEPY_MIGRATE=on
16LOCAL_DJANGO_SECRET_KEY='!!!DODGY_LOCAL_SECRET!!!'
17LOCAL_DJANGO_SETTINGS_MODULE='config.settings.local'
18LOCAL_DJANGO_TEMPLATES_CSS="/static/css/styles.css"
19LOCAL_MEDIA_URL='media-lo/'
20LOCAL_STATIC_URL='static-lo/'
21# static options are Local or S3
22LOCAL_USE_STATIC='Local'
23LOCAL_TAILWIND_CSS_DEV=True
24
25# Local Environment S3 access
26LOCAL_AWS_ACCESS_KEY_ID=""
27# If using the default leave ENDPOINT_URL unset
28LOCAL_AWS_S3_ENDPOINT_URL=""
29# If using the default leave AWS_LOCATION unset
30LOCAL_AWS_LOCATION=""
31LOCAL_AWS_SECRET_ACCESS_KEY=""
32LOCAL_AWS_S3_REGION_NAME=""
33LOCAL_AWS_S3_OBJECT_PARAMETERS=""
34LOCAL_AWS_STORAGE_BUCKET_NAME=""
35
36# Local Environment Email Settings
37LOCAL_EMAIL_BACKEND="django.core.mail.backends.console.EmailBackend"
38LOCAL_EMAIL_HOST=""
39LOCAL_EMAIL_PORT=""
40LOCAL_EMAIL_HOST_USER=""
41LOCAL_EMAIL_HOST_PASSWORD=""
42LOCAL_EMAIL_USE_TLS=""
Staging and Production#
Staging
and Production
environments add the environment prefix 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
1# Production Environment ENV Keys
2
3# Production Environment Django
4PROD_ALLOWED_HOSTS=''
5PROD_DATABASE_URL=''
6PROD_DB_API_KEY=''
7PROD_DJANGO_DEBUG=False
8PROD_DJANGO_INTERNAL_IPS=[]
9PROD_DJANGO_LOG_FILE='logging/rotating.log'
10PROD_DJANGO_LOGGING_LEVEL='INFO'
11PROD_DJANGO_LOGGING_MAIL_ADMINS='ERROR'
12# For the docker image
13PROD_DJANGO_MANAGEPY_MIGRATE=on
14PROD_DJANGO_SECRET_KEY=='!!!INSECURE_PRODUCTION_SECRET!!!'
15PROD_DJANGO_SETTINGS_MODULE='config.settings.production'
16PROD_DJANGO_TEMPLATES_CSS=''
17PROD_MEDIA_URL='media-'
18PROD_STATIC_URL='static/'
19# static options are local or S3
20PROD_USE_STATIC='S3'
21PROD_TAILWIND_CSS_DEV=False
22
23# Production Environment S3 access
24PROD_AWS_ACCESS_KEY_ID=''
25# If using the default leave ENDPOINT_URL unset
26PROD_AWS_S3_ENDPOINT_URL=''
27# If using the default leave AWS_LOCATION unset
28PROD_AWS_LOCATION=''
29PROD_AWS_SECRET_ACCESS_KEY=''
30PROD_AWS_S3_REGION_NAME=''
31PROD_AWS_S3_OBJECT_PARAMETERS=''
32PROD_AWS_STORAGE_BUCKET_NAME=''
33
34# Production Environment Email Settings
35PROD_EMAIL_BACKEND=''
36PROD_EMAIL_HOST=''
37PROD_EMAIL_PORT=''
38PROD_EMAIL_HOST_USER=''
39PROD_EMAIL_HOST_PASSWORD=''
40PROD_EMAIL_USE_TLS=''
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 production settings file extract below.
1PROD_DJANGO_LOG_FILE='logging/rotating.log'
2PROD_DJANGO_LOGGING_LEVEL='INFO'
3PROD_DJANGO_LOGGING_MAIL_ADMINS='ERROR'