Python / Django:在runserver下登录到控制台,在Apache下登录到文件 [英] Python/Django: log to console under runserver, log to file under Apache

查看:108
本文介绍了Python / Django:在runserver下登录到控制台,在Apache下登录到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在下运行我的Django应用程序时,如何将跟踪消息发送到控制台(例如 print )manage.py runserver ,但是当我在Apache下运行应用程序时,将这些消息发送到日志文件?



我查看了 Django日志记录,虽然我对其高级用途的灵活性和可配置性印象深刻,但我仍然以如何处理我的简单用例。

解决方案

在mod_wsgi下运行时,打印到stderr的文本将显示在httpd的错误日志中。您可以直接使用 print ,或者使用记录

  print>> sys.stderr,'再见,残酷的世界!'


How can I send trace messages to the console (like print) when I'm running my Django app under manage.py runserver, but have those messages sent to a log file when I'm running the app under Apache?

I reviewed Django logging and although I was impressed with its flexibility and configurability for advanced uses, I'm still stumped with how to handle my simple use-case.

解决方案

Text printed to stderr will show up in httpd's error log when running under mod_wsgi. You can either use print directly, or use logging instead.

print >>sys.stderr, 'Goodbye, cruel world!'

这篇关于Python / Django:在runserver下登录到控制台,在Apache下登录到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆