I've added the following logging configuration to my Django App's settings.py
file:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
},
}
Now, I simply want to add some custom log records to one of my views in views.py
, but it appears the logger is NOTSET
, which means only levels of warning
and higher are logged:
import logging
from django.http import JsonResponse
logger = logging.getLogger(__name__)
def testing(request):
logger.info("Doesn't show...")
logger.warning(f"Log Level: {logger.level} = {logging.getLevelName(logger.level)}")
return JsonResponse({"Hello": "World"})
The snippet above logs the following:
Log Level: 0 = NOTSET
Am I doing something wrong? Why is the logger's level not set (even though I clearly set it in settings.py
)?