-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #561 from openstax/logging
Update Django logging to use Sentry
- Loading branch information
Showing
3 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# Django settings for openstax project. | ||
|
||
import os | ||
import raven | ||
import logging.config | ||
from django.utils.log import DEFAULT_LOGGING | ||
|
||
PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..', '..') | ||
BASE_DIR = PROJECT_ROOT | ||
|
@@ -162,6 +165,7 @@ | |
'rest_framework', | ||
'rest_framework.authtoken', | ||
'rest_auth', | ||
'raven.contrib.django.raven_compat', | ||
#'social.apps.django_app.default', | ||
'social_django', | ||
'storages', | ||
|
@@ -223,45 +227,101 @@ | |
# the site admins on every HTTP 500 error when DEBUG=False. | ||
# See http://docs.djangoproject.com/en/dev/topics/logging for | ||
# more details on how to customize your logging configuration. | ||
LOGGING = { | ||
# LOGGING = { | ||
# 'version': 1, | ||
# 'disable_existing_loggers': False, | ||
# 'filters': { | ||
# 'require_debug_false': { | ||
# '()': 'django.utils.log.RequireDebugFalse' | ||
# } | ||
# }, | ||
# 'formatters': { | ||
# 'simple': { | ||
# 'format': '%(levelname)s %(asctime)s %(module)s %(message)s' | ||
# }, | ||
# }, | ||
# 'handlers': { | ||
# 'mail_admins': { | ||
# 'level': 'ERROR', | ||
# 'filters': ['require_debug_false'], | ||
# 'class': 'django.utils.log.AdminEmailHandler' | ||
# }, | ||
# 'file': { | ||
# 'level': 'ERROR', | ||
# 'class': 'logging.FileHandler', | ||
# 'filename': 'server.log', | ||
# 'formatter': 'simple' | ||
# }, | ||
# }, | ||
# 'loggers': { | ||
# 'django.request': { | ||
# 'handlers': ['mail_admins'], | ||
# 'level': 'ERROR', | ||
# 'propagate': True, | ||
# }, | ||
# 'accounts.salesforce': { | ||
# 'handlers': ['file'], | ||
# 'level': 'ERROR', | ||
# 'propagate': True, | ||
# 'formatter': 'simple', | ||
# }, | ||
# }, | ||
# } | ||
|
||
LOGGING_CONFIG = None | ||
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper() | ||
logging.config.dictConfig({ | ||
'version': 1, | ||
'disable_existing_loggers': False, | ||
'filters': { | ||
'require_debug_false': { | ||
'()': 'django.utils.log.RequireDebugFalse' | ||
} | ||
}, | ||
'formatters': { | ||
'simple': { | ||
'format': '%(levelname)s %(asctime)s %(module)s %(message)s' | ||
'default': { | ||
# exact format is not important, this is the minimum information | ||
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s', | ||
}, | ||
'django.server': DEFAULT_LOGGING['formatters']['django.server'], | ||
}, | ||
'handlers': { | ||
'mail_admins': { | ||
'level': 'ERROR', | ||
'filters': ['require_debug_false'], | ||
'class': 'django.utils.log.AdminEmailHandler' | ||
# console logs to stderr | ||
'console': { | ||
'class': 'logging.StreamHandler', | ||
'formatter': 'default', | ||
}, | ||
'file': { | ||
'level': 'ERROR', | ||
'class': 'logging.FileHandler', | ||
'filename': 'server.log', | ||
'formatter': 'simple' | ||
# Add Handler for Sentry for `warning` and above | ||
'sentry': { | ||
'level': 'WARNING', | ||
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', | ||
}, | ||
'django.server': DEFAULT_LOGGING['handlers']['django.server'], | ||
}, | ||
'loggers': { | ||
'django.request': { | ||
'handlers': ['mail_admins'], | ||
'level': 'ERROR', | ||
'propagate': True, | ||
# default for all undefined Python modules | ||
'': { | ||
'level': 'WARNING', | ||
'handlers': ['console', 'sentry'], | ||
}, | ||
# Our application code | ||
'openstax': { | ||
'level': LOGLEVEL, | ||
'handlers': ['console', 'sentry'], | ||
# Avoid double logging because of root logger | ||
'propagate': False, | ||
}, | ||
'accounts.salesforce': { | ||
'handlers': ['file'], | ||
# Prevent noisy modules from logging to Sentry | ||
'noisy_module': { | ||
'level': 'ERROR', | ||
'propagate': True, | ||
'formatter': 'simple', | ||
'handlers': ['console'], | ||
'propagate': False, | ||
}, | ||
# Default runserver request logging | ||
'django.server': DEFAULT_LOGGING['loggers']['django.server'], | ||
}, | ||
}) | ||
# this is what sends tracebacks to Sentry | ||
RAVEN_CONFIG = { | ||
'dsn': 'https://2e1ecafc60684f86b59c654de3032d83:[email protected]/11', | ||
# If you are using git, you can also automatically configure the | ||
# release based on the git info. | ||
'release': raven.fetch_git_sha(os.path.dirname(os.pardir)), | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters