Nimish Bansal
Nimish Bansal

Reputation: 1759

How to stop logging sending message of length in django/python

In my settings.py Django project I have my LOGGING dict as

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'loggers': {
        '': {
            'handlers': ['sentry'],
            'level': 'DEBUG',
            'propagate': False,
        },
    },
    'handlers': {
        'sentry': {
            'level': 'DEBUG',
            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler'
        }
    }
}

Now my problem is as soon as I execute logging.debug("hello")

It prints a message in my console that is

b'Sending message of length 781 to https://sentry.io/api/12345/store/'

It succesfully logs to sentr but how can I get rid of this message printing in my console?

Upvotes: 1

Views: 46

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476594

The name of your logger is the empty string. This means that it is the "root logger". If you then later use logging, you will again use that logger.

You can simply set a name of the logger, for example to 'sentrylogger':

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'loggers': {
        # set the name of the logger to a non-empty string
        'sentrylogger': {
            'handlers': ['sentry'],
            'level': 'DEBUG',
            'propagate': False,
        },
    },
    'handlers': {
        'sentry': {
            'level': 'DEBUG',
            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler'
        }
    }
}

Of course if you make a logger later, you should not name it 'sentrylogger'. For example:

import logging

logger = logging.getLogger('sentrylogger')

logger.debug('hello')

will again yield the same behavior. So as long as you give the logger a different name, or you use the root logger, there is no problem.

Upvotes: 1

Related Questions