I seen How do I disable log messages from the Requests library? and I was wondering, how could i use django to manage these settings? Essentially, the problem is the Requests
library is overly verbose and I want to tune it's logging level to warning
or even error
.
Our logs are FILLED with these:
INFO - requests.packages.urllib3.connectionpool (_new_conn:735)
Starting new HTTPS connection (1): www.example.com
INFO - requests.packages.urllib3.connectionpool (_new_conn:735)
Starting new HTTPS connection (1): localhost
Here is my current Django logging configuration with what I would think would be the fix to the library being overly verbose. But it isn't working.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': ' '.join(['%(asctime)s', '%(levelname)8s', '- %(name)s',
'(%(funcName)s:%(lineno)d)', os.sep, ' ' * 4, '%(message)s']),
'datefmt': DATEFORMAT,
},
'default': {
'format': ' '.join(['%(asctime)s', '%(levelname)8s', '- %(message)s']),
'datefmt': DATEFORMAT,
},
'syslog': {
'format': ' '.join([PROCTITLE + '[%(process)d]', '[%(levelname)s]', '(%(module)s %(funcName)s:%(lineno)d)',
'- %(message)s']),
'datefmt': DATEFORMAT,
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'null': {
'level': HANDLER_LEVEL,
'class': 'django.utils.log.NullHandler',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
},
'console_handler': {
'level': parser.get('logging', 'handler.console.level'),
'formatter': 'verbose',
'class': 'ppcc.lib.logs.TwistedStreamHandler',
},
'default': {
'level': HANDLER_LEVEL,
'formatter': 'syslog',
'class': 'logging.handlers.SysLogHandler',
'address': '/dev/log',
'facility': 20,
},
},
'loggers': {
'django': {
'handlers': ['default'],
'propagate': True,
'level': parser.get_log_level('django'),
},
'django.request': {
'handlers': ['mail_admins', 'default'],
'level': 'ERROR',
'propagate': False,
},
'boto': {
'handlers': DEFAULT_HANDLERS,
'level': 'WARNING',
},
'requests': {
# The requests library is too verbose in it's logging, reducing the verbosity in our logs.
'handlers': DEFAULT_HANDLERS,
'level': 'WARNING',
'propagate': True,
},
'urllib3': {
'handers': DEFAULT_HANDLERS,
'level': 'WARNING',
'propagate': True
},
'cassandra': {
'handlers': DEFAULT_HANDLERS,
'level': 'WARNING',
},
'cqlengine': {
'handlers': DEFAULT_HANDLERS,
'propagate': True,
'level': 'WARNING',
},
'': {
'handlers': DEFAULT_HANDLERS,
'level': LOG_LEVEL,
},
}
}
I believe the following would work:
import logging
logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.ERROR)
You can retrieve the existing logger and manipulate it. I similarly had a mouthy submodule, and another option just to shut it up entirely is to set propagate = False
on the logger.
The correct solution was what I had thought it was, just adding it to the LOGGING
setting in `settings.py'
'requests': {
# The requests library is too verbose in it's logging, reducing the verbosity in our logs.
'handlers': DEFAULT_HANDLERS,
'level': 'WARNING',
},
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