我可以让 nginx error_log 保存整个堆栈跟踪吗?

我可以让 nginx error_log 保存整个堆栈跟踪吗?

我有一个在 fastcgi 上运行的 Django 应用程序,当出现异常时,它似乎在日志中被截断error.log

2012/06/10 19:25:55 [error] 1416#0: *19219 FastCGI sent in stderr: "Traceback (most recent call last):
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/flup/server/fcgi_base.py", line 574, in run
    protocolStatus, appStatus = self.server.handler(self)
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/flup/server/fcgi_base.py", line 1159, in handler
    result = self.application(environ, start_response)
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 273, in __call__
    response = self.get_response(request)
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/django/core/handlers/base.py", line 169, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/django/core/handlers/base.py", line 209, in handle_uncaught_exception
    'request':request
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1154, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1246, in _log
    self.handle(record)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1256, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 1293, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python2.7/logging/__init__.py", line 740, in handle
    self.emit(record)
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/django/utils/log.py", line 101, in emit
    html_message=html_message)
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/django/core/mail/__init__.py", line 96, in mail_admins
    mail.send(fail_silently=fail_silently)
  File "/home/deploy/.virtualenv/mediapop/lib/python2.7/site-packages/django/core/mail/message.py", line 251, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/deploy/.virtualenv/mediapop/li

我可以补救一下,以便获得完整的堆栈跟踪吗?

答案1

我建议将 Web 服务器错误日志和应用程序错误日志分开保存。这样可以巧妙地将堆栈分为两个层,因为 Web 服务器日志将包含 http 级错误,而应用程序日志将包含代码抛出的异常以及您生成的其他自定义日志。

这个帖子有关于 Django 错误日志的更多信息,包括用于记录 Django 堆栈跟踪的其他选项的建议。

相关内容