I just got sentry working in my environment and I tried tweaking my logging to make it stop sending error emails, but it still is and I don't understand why. My logging config is:
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"format": '%(levelname)s %(asctime)s (%(pathname)s %(funcName)s): "%(message)s"'
},
"simple": {"format": "%(levelname)s %(message)s"},
"django.server": {
"()": "django.utils.log.ServerFormatter",
"format": "[%(server_time)s] %(message)s",
},
},
"handlers": {
"null": {"level": "DEBUG", "class": "logging.NullHandler",},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "simple",
},
"log_file": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
"filename": "/var/log/courtlistener/django.log",
"maxBytes": "16777216", # 16 megabytes
"formatter": "verbose",
},
"django.server": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "django.server",
},
},
"loggers": {
# Disable SuspiciousOperation.DisallowedHost exception ("Invalid
# HTTP_HOST" header messages.) This appears to be caused by clients that
# don't support SNI, and which are browsing to other domains on the
# server. The most relevant bad client is the googlebot.
"django.security.DisallowedHost": {
"handlers": ["null"],
"propagate": False,
},
"django.server": {
"handlers": ["django.server"],
"level": "INFO",
"propagate": False,
},
# This is the one that's used practically everywhere in the code.
"cl": {"handlers": ["log_file"], "level": "INFO", "propagate": True,},
},
}
Is there a missing piece here? I don't know how that'd possibly send emails. Is there another config variable I should be thinking about?
UPDATE: One thing I've noticed is that I get plaintext error emails now instead of the HTML ones I used to get. This changed when I tweaked the logging config, but I have no idea why and Googling it doesn't seem to reveal anything.
Disabling logging configuration If you don't want to configure logging at all (or you want to manually configure logging using your own approach), you can set LOGGING_CONFIG to None . This will disable the configuration process for Django's default logging.
By default, Django uses the dictConfig format. In order to configure logging, you use LOGGING to define a dictionary of logging settings.
The Django One-Click application employs Gunicorn and Upstart. Application level logging can be found in /var/log/upstart/gunicorn. log By default, Gunicorn logs to stderr and Upstart will collect output to stderr/stdout in /var/log/upstart/$JOB_NAME.
Server errorsWhen DEBUG is False , Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater).
Django setups a default mail_admins
handler, which you can't simply replace in the handlers
section, so if you want to get rid of it you need to overwrite the handlers
in the root logger:
All loggers except django.server propagate logging to their parents, up to the root django logger. The console and mail_admins handlers are attached to the root logger to provide the behavior described above.
LOGGING = {
'loggers': {
'django': {
'handlers': [],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'propagate': False,
},
},
}
[edit] fixed wrong statement about overwriting the handler class, sadly it doesn't work as expected, seems to be hard-coded in some way (too busy to look it up in the django code base).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With