I can\'t get logging to work in my Django web app.
My settings file looks like this:
EMAIL_HOST = \"smtp.gmail.com\"
EMAIL_PORT = 465
EMAIL_HOST_USE
This is my working setup. I have not added a console logger
, as I am using it only to production. The inspiration came from the relevant Logging Examples of Django docs.
Here are my email and logging settings:
from os.path import join
# Email Configuration ==========================================================
ADMINS = [('Me', 'my@email'), ]
MANAGERS = ADMINS
DEFAULT_FROM_EMAIL = 'from@email'
SERVER_EMAIL = 'error_from@email'
EMAIL_HOST = 'smtp.server'
EMAIL_HOST_USER = 'username_for_login'
EMAIL_HOST_PASSWORD = 'password_for_login'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
# Logging Configuration ========================================================
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': join(HOME_DIR, 'my_logs', 'debug.log'),
'formatter': 'verbose'
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'formatter': 'simple'
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'ERROR',
'propagate': True,
},
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
},
}
I have spotted two errors to your environment variables:
TLS
and therefore the correct port should be 587.Moreover, you are trying to use Google as an SMTP server, but according to this updated answer this service is no longer available from google and you have to search for another SMTP server.
I have also assembled a post with a couple debugging techniques if you need to use.