django.request logger not propagated to root?

后端 未结 3 503
面向向阳花
面向向阳花 2020-12-23 03:55

Using Django 1.5.1:

DEBUG = False

LOGGING = {
    \'version\': 1,
    \'disable_existing_loggers\': True,
    \'formatters\': {
        \'verbose\': {
               


        
3条回答
  •  攒了一身酷
    2020-12-23 04:34

    Ok, so the behavior is "correct", but not expected. django/conf/__init__.py:65:

    def _configure_logging(self):
        ...
        if self.LOGGING_CONFIG:
            from django.utils.log import DEFAULT_LOGGING
            # First find the logging configuration function ...
            logging_config_path, logging_config_func_name = self.LOGGING_CONFIG.rsplit('.', 1)
            logging_config_module = importlib.import_module(logging_config_path)
            logging_config_func = getattr(logging_config_module, logging_config_func_name)
    
            logging_config_func(DEFAULT_LOGGING)
    
            if self.LOGGING:
                # Backwards-compatibility shim for #16288 fix
                compat_patch_logging_config(self.LOGGING)
    
                # ... then invoke it with the logging settings
                logging_config_func(self.LOGGING)
    

    What is happening is that default logging configuration is applied and django.request logger is created. Then my custom LOGGING configuration is applied with disable_existing_loggers = True, but Python doesn't delete already existing logger django.request, but only disables it.

    So I have to manually reconfigure django.request logger in my configuration. :(

提交回复
热议问题