2012-08-14 47 views
1

我正在嘗試調試this code。有了這個目標,我試圖在this tutorial之後使用日誌記錄。有了這個目標,我在我的腳本插入此代碼:如何查看GAE下的日誌模塊輸出模塊?

import logging 

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') 

logging.debug('This is a log message.') 

而且,在我想要得到的消息記錄的部分,我插入的行:logging.debug ('This is a log message.')這樣:

def fcount(self,f,cat): 
    res = db.GqlQuery("SELECT * FROM fc WHERE feature =:feature AND category =:category", feature = f, category = cat).get() 
    logging.debug('This is a log message.') 
# res=self.con.execute(
#  'select count from fc where feature="%s" and category="%s"' 
#  %(f,cat)).fetchone() 
    if res is None: return 0 
    else: 
     res = fc.count 
     return float(res) 

它事實證明我的申請是一個GAE申請。我看不到日誌消息,它沒有出現在瀏覽器或PyScripter IDE中。我應該在哪裏看到日誌消息的屏幕?

PS - 我想利用這個代碼寫交替記錄消息記錄到文件:

import logging 
logging.basicConfig(filename='log_filename.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') 
logging.debug('This is a log message.') 

但我發現一個I/O錯誤。

+0

+1陳述的問題 – msw 2012-08-14 01:47:35

回答

1

您是試圖在Google App Engine上運行記錄器還是在本地計算機上無法運行?如果它不適用於GAE,那是因爲您已將記錄器設置爲寫入文件,而GAE並不真正讓您訪問文件系統。

對於非基於文件的日誌,您可以在GAE管理控制檯中找到日誌。 (在你的本地主機,它位於

http://localhost:8080/_ah/admin 

參見如何使用GAE上運行日誌模塊https://developers.google.com/appengine/articles/logging

+0

這解釋了I/O錯誤。我使用GAE日誌控制檯,但我認爲用這種方法我可以得到更詳細的日誌消息。謝謝! – craftApprentice 2012-08-14 01:40:59

+0

NP,很高興我能服務。 – Wulfram 2012-08-14 01:44:27

+1

@Wulfram本地主機管理員沒有日誌消息(至少不是我的)。日誌在終端窗口中可見。 – aschmid00 2012-08-14 13:30:10

1

,我不能給你PyScripter細節,但你需要設置你的IDE通該-d(或--debug)標誌的dev_appserver.py這使DEBUG日誌,否則你會看到INFO或更高級別的唯一消息

所以,你可以嘗試,而不是:

logging.info('This is a log message.')