vdboor
vdboor

Reputation: 22526

Prevent duplicate output for errors in Python logger

I get duplicate logging output for exceptions and errors in my pythong LOGGING confirmation. It makes sense given the configuration:

LOGGING = {
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'sentry': {
            'level': 'WARNING',
            'class': 'raven.contrib.django.handlers.SentryHandler',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        },
    },
    'root': {
        'level': 'ERROR',   # Give me errors only
        'handlers': ['mail_admins', 'sentry', 'console'],
    },
    'apps.order_shipping': {
        # This module needs extra debugging, but now ERROR is duplicated
        'handlers': ['console'],
        'level': 'DEBUG',
    },
}

how can I implement this in a better way? I'd like to enable verbosity for some modules, without causing duplication of ERROR messages.

Upvotes: 1

Views: 1228

Answers (1)

stalk
stalk

Reputation: 12054

Set propagate to False:

{
# ...
    'apps.order_shipping': {
        # This module needs extra debugging, but now ERROR is duplicated
        'handlers': ['console'],
        'level': 'DEBUG',
        'propagate': False,
    },
}

Upvotes: 3

Related Questions