-
-
Save benthomasson/d6be7aeaee08547adb3ea1aeb546a46a to your computer and use it in GitHub Desktop.
Django logging example
This file contains hidden or 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
| import logging.config | |
| import os | |
| from django.utils.log import DEFAULT_LOGGING | |
| # Disable Django's logging setup | |
| LOGGING_CONFIG = None | |
| LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper() | |
| logging.config.dictConfig({ | |
| 'version': 1, | |
| 'disable_existing_loggers': False, | |
| 'formatters': { | |
| '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': { | |
| # console logs to stderr | |
| 'console': { | |
| 'class': 'logging.StreamHandler', | |
| 'formatter': 'default', | |
| }, | |
| 'django.server': DEFAULT_LOGGING['handlers']['django.server'], | |
| }, | |
| 'loggers': { | |
| # default for all undefined Python modules | |
| '': { | |
| 'level': 'WARNING', | |
| 'handlers': ['console'], | |
| }, | |
| # Our application code | |
| 'app': { | |
| 'level': LOGLEVEL, | |
| 'handlers': ['console'], | |
| # Avoid double logging because of root logger | |
| 'propagate': False, | |
| }, | |
| # Prevent noisy modules from logging to Sentry | |
| 'noisy_module': { | |
| 'level': 'ERROR', | |
| 'handlers': ['console'], | |
| 'propagate': False, | |
| }, | |
| # Default runserver request logging | |
| 'django.server': DEFAULT_LOGGING['loggers']['django.server'], | |
| }, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment