How do you log server errors on django sites(你如何在 django 网站上记录服务器错误)
问题描述
So, when playing with the development I can just set settings.DEBUG
to True
and if an error occures I can see it nicely formatted, with good stack trace and request information.
But on kind of production site I'd rather use DEBUG=False
and show visitors some standard error 500 page with information that I'm working on fixing this bug at this moment ;)
At the same time I'd like to have some way of logging all those information (stack trace and request info) to a file on my server - so I can just output it to my console and watch errors scroll, email the log to me every hour or something like this.
What logging solutions would you recomend for a django-site, that would meet those simple requirements? I have the application running as fcgi
server and I'm using apache web server as frontend (although thinking of going to lighttpd).
Well, when DEBUG = False
, Django will automatically mail a full traceback of any error to each person listed in the ADMINS
setting, which gets you notifications pretty much for free. If you'd like more fine-grained control, you can write and add to your settings a middleware class which defines a method named process_exception()
, which will have access to the exception that was raised:
http://docs.djangoproject.com/en/dev/topics/http/middleware/#process-exception
Your process_exception()
method can then perform whatever type of logging you'd like: writing to console, writing to a file, etc., etc.
Edit: though it's a bit less useful, you can also listen for the got_request_exception
signal, which will be sent whenever an exception is encountered during request processing:
http://docs.djangoproject.com/en/dev/ref/signals/#got-request-exception
This does not give you access to the exception object, however, so the middleware method is much easier to work with.
这篇关于你如何在 django 网站上记录服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:你如何在 django 网站上记录服务器错误


- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- 沿轴计算直方图 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01