2013-12-14 48 views
0

更具體地說:我怎樣才能得到與django中的appengine(GAE)類似的日誌系統?

  1. 簡單的函數調用。如logging.info(msg)
  2. 按要求分類。
  3. 從管理控制檯中查看。

django不是必需的。任何框架都可以,甚至是一個單獨的Python庫。

+0

這聽起來多餘。我不明白爲什麼你不只是使用logging.info() – dragonx

+0

@dragonx,但我怎樣才能檢查它在web視圖? – Topro

+0

https://developers.google.com/appengine/docs/python/logs/ –

回答

0

logging module是一個內置的Python,不僅適用於Google App Engine。爲整合管理面板

DEBUG:root:This message should go to the log file 
INFO:root:So should this 
WARNING:root:And this, too 

:你想要的東西很簡單,只需使用logging.basicConfig()

import logging 
logging.basicConfig(level=logging.DEBUG) 
logging.debug('This message should go to the log file') 
logging.info('So should this') 
logging.warning('And this, too') 

Logging Module Doc

,輸出會是這樣:

藉此它有所不同,取決於你使用的框架,你可以添加一個參數filebasicConfig ask logg荷蘭國際集團模塊保存日誌文件,那麼你可以讀它,分析它在Django

比如,它是:

logging.basicConfig(file="admin.log",level=logging.DEBUG) 

是你想要的嗎?