开发者

django logging: log is not created

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'开发者_StackOverflowt 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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜