28👍
✅
Calling logger = logging.getLogger(__name__)
causes the logging
module to search for a logger named as your module (demo.views
); as you have no logger defined by that name, it fails. To simply log to console, you can use the django
logger defined in 'loggers'
key of your LOGGING
configuration:
import logging
logger = logging.getLogger('django')
def demo_logging(request, template):
logger.error("Got some error")
return render(request, template)
Source:stackexchange.com