我在Heroku上创建了一个应用程序,然后将我的Django应用程序推送到它。
我使用DEBUG=false
监控日志,以便实时查看。
如何在这样的生产环境中详细显示400错误日志(debug.technical_500_response(request, *exc_info)
时)?
我知道handler500=my_custom_exception_logger.server_error
方法,并通过重写handler500来记录400错误
(例如technical_400_response
)。
但似乎没有Django 1.11.5
Python 3.6.1
whitenoise 3.3.0
方法。
我正在使用
web: gunicorn --env DJANGO_SETTINGS_MODULE=myapp.settings myapp.wsgi --log-file -
Procfile
LOGGING = {
'version': 1,
'formatters': {
'all': {
'format': '\t'.join([
"[%(levelname)s]",
"asctime:%(asctime)s",
"module:%(module)s",
"message:%(message)s",
"process:%(process)d",
"thread:%(thread)d",
])
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'django.log'),
'formatter': 'all',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'all'
},
},
'loggers': {
'command': {
'handlers': ['file', 'console'],
'level': 'DEBUG',
},
},
}
settings.py
{{1}}
提前致谢。
答案 0 :(得分:0)
在这种情况下,为我调试400错误的最佳方法是使用chrome developer console。
if item.is_valid():
// do some thing...
else:
return Response(item.errors, status=status.HTTP_400_BAD_REQUEST)
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function()
{
if( this.readyState == 4 && this.status == 200 )
{
if( this.response )
{
var res = this.response;
console.log(this.response);
// do something...
}
}
}
...
然后测试了对我的django服务器的POST请求,responseText告诉我它失败的原因。