django 日志记录:未创建日志
我正在 GAE 开发服务器上运行我的应用程序,并使用 app-engine-patch 来运行 Django。 我的一个观点被窃听了,所以我想记录发生的一切。
我在 myapp.views: 中添加了:
import logging
LOG_FILENAME = '/mylog.txt'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
我的功能是:
def function(string):
logging.debug('new call')
#do stuff
#logging.debug('log stuff')
我的问题是找不到日志。当我运行我的应用程序时,我没有收到任何错误,但未创建日志。 我还尝试了各种路径: /mylog.txt 、mylog.txt 、 c:\mylog.txt、c:\complete\path\to \my\app\mylog.txt ,但它不起作用。
另一方面,我尝试创建并运行一个单独的测试: #测试.py 导入日志记录
LOG_FILENAME = '/mylog.txt'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug('test')
并且创建日志没有问题: c:\mylog.txt
我不熟悉日志记录,所以我不知道 django 或 appengine 是否存在一些问题。
谢谢
I'm running my app on the GAE development server, with app-engine-patch to run Django.
One of my views is bugged , so I want to log everything that happens.
I added in myapp.views:
import logging
LOG_FILENAME = '/mylog.txt'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
and my function is:
def function(string):
logging.debug('new call')
#do stuff
#logging.debug('log stuff')
My problem is that I can't find the log. When I run my app I get no errors, but the log is not created.
I also tried various paths: /mylog.txt ,mylog.txt , c:\mylog.txt, c:\complete\path\to \my\app\mylog.txt, but it doesn't work.
On the other hand I tried to create and run a separate test:
#test.py
import logging
LOG_FILENAME = '/mylog.txt'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug('test')
And the log is created without problems: c:\mylog.txt
I'm not familiar with logging so I don't know if there might be some issues with django, or appengine.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜问题是您将日志配置放在视图中。 django 日志记录的一般经验法则是在 settings.py 中设置日志配置。
I am guessing the problem is that you put your log configuration in a view. A general rule of thumb for django logging is to set the log configuration in your settings.py.
默认情况下,dev_appserver 会抑制调试日志。要打开它,请使用
--debug
选项运行它。请注意,dev_appserver 本身使用相同的记录器,并且会输出大量您可能不关心的调试内容。您的日志记录将打印到 stderr。
By default, dev_appserver suppresses the debug log. To turn it on, run it with the
--debug
option. Note that dev_appserver itself uses the same logger, and will spew lots of debugging stuff you might not care about.Your logging will print to stderr.
您无法写入 App Engine 上的文件 - 因此,任何记录到文本文件的尝试也注定会失败。日志输出将出现在开发中的 SDK 控制台上,或生产中的日志控制台中。
You can't write to files on App Engine - thus, any attempt to log to text files is also doomed to failure. Log output will appear on the SDK console in development, or in the logs console in production.