简体   繁体   中英

How to maintain the log name for an unhandled exception in Django

I am a bit lost about the logging topic.

I declare all my loggers with logger = logging.getLogger(__name__) so when logging I have this info available. However, if an unhandled exception happens, I know that Django logs the exception with log name as django.request and so on because of this https://docs.djangoproject.com/en/4.0/ref/logging/#loggers , but what if I would like to use the log name I have declared? I know I am not actually calling the logger when the exception happens, but I would like to know the originary module for the exception. Any ideas?

Thanks!

The exception should have a traceback printed in the log, even if it was logged against django.request , and that should point to where the problem occurred / what it was. Otherwise, you will have to catch the exceptions yourself (in potentially each of your views) and log them as you see fit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM