3

I am using Django 3.1. I would like to see if I can use async to handle my webhook so as to give a faster response.

From Async View, it states that:

Middleware can be built to support both sync and async contexts. Some of Django’s middleware is built like this, but not all. To see what middleware Django has to adapt, you can turn on debug logging for the django.request logger and look for log messages about “Synchronous middleware … adapted”.

My question is how to turn on my logger to check it?

I tried to add logger config to my settings.py. After that, I call logger.debug('in index') in a test function but nothing is shown. I cannot find the log messages “Synchronous middleware … adapted”.

LOGGING = {  
 'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'root': {
        'handlers': ['console'],
        'level': 'WARNING',
    },
    'loggers': {
        'django.request': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
            'propagate': False,
        },
    },
}
Benny Chan
  • 730
  • 1
  • 8
  • 24

1 Answers1

0

You need to set up loggers like this:

LOGGING = {  
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
            'propagate': False,
        },
    },
}

Note the loglevel 'DEBUG' in logger settings.

But it doesn't give you the full list of middleware and their modes. It just shows the middleware, which were adapted.

Som-1
  • 601
  • 7
  • 16