Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added celery logging hook to enable logging celery exceptions #1285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions formhub/preset/smtp_debugging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# To use, run an smtpd.DebuggingServer in a separate shell
# $ sudo python -m smtpd -c DebuggingServer -n localhost:25
#
# Then test by running a shell with this as the settings file
# $ python manage.py shell --settings=formhub.preset.smtp_debugging
# > import logging
# > logger = logging.getLogger('django.request')
# > logger.log('A celery error occurred')
#
# You should see an email message on the smtpd.DebuggingServer's shell
#
from formhub.settings import *

DEBUG = False

EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
ADMINS = (
('Admin', '[email protected]'),
)
15 changes: 13 additions & 2 deletions formhub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import subprocess
import sys

import logging
from django.core.exceptions import SuspiciousOperation

from django.utils.log import AdminEmailHandler
from celery.signals import after_setup_logger
from pymongo import MongoClient


import djcelery


djcelery.setup_loader()

CURRENT_FILE = os.path.abspath(__file__)
Expand Down Expand Up @@ -324,6 +327,14 @@ def skip_suspicious_operations(record):
}
}


def configure_logging(logger, **kwargs):
admin_email_handler = AdminEmailHandler()
admin_email_handler.setLevel(logging.ERROR)
logger.addHandler(admin_email_handler)

after_setup_logger.connect(configure_logging)

MONGO_DATABASE = {
'HOST': 'localhost',
'PORT': 27017,
Expand Down