def test_default_logging_dict(self): msg = 'log message test_default_logging_dict' with capture_stderr() as output: with temp_directory() as td: d = default_logging_dict(td, handlers=['default', 'file']) logging.config.dictConfig(d) logger = logging.getLogger(__name__) logger.debug(msg) self._flush_logging() logfile = os.path.abspath(os.path.join(td, 'debug.log')) self.assert_in_file(msg, logfile) self.assertIn(msg, output.getvalue())
def django_logging_dict(log_dir, handlers=['file'], filename='debug.log'): """Extends :func:`wrench.logtools.utils.default_logging_dict` with django specific values. """ d = default_logging_dict(log_dir, handlers, filename) d['handlers'].update({ 'mail_admins':{ 'level':'ERROR', 'class':'django.utils.log.AdminEmailHandler', } }) d['loggers'].update({ 'django.db.backends': { # stop SQL debug from going to main logger 'handlers': ['file', 'mail_admins'], 'level': 'ERROR', 'propagate': False, }, 'django.request': { 'handlers': ['file', 'mail_admins'], 'level': 'ERROR', 'propagate': False, }, }) return d