0
我想在模塊日誌記錄中設置Python 2.7中的RotatingFileHandler,但無論我做什麼,我只能獲取寫入日誌文件的頂級腳本。Python 2.7 RotatingFileHandler無法從模塊登錄
這是我在我的前Script代碼:
import logging
import Lib.download as d
LOG_FILE = public_dir + "\script2.log"
log = logging.getLogger('Script_2')
log.setLevel(logging.DEBUG)
rotate_handler = handlers.RotatingFileHandler(LOG_FILE, maxBytes = 5000, backupCount=5)
log_format = logging.Formatter('%(asctime)s %(name)-8s:%(levelname)s:%(message)s')
rotate_handler.setFormatter(log_format)
log.addHandler(rotate_handler)
log.debug('Launching meat of script_2')
d.some_function()
log.info('script_2 completed successfully')
一個模塊 '下載' 代碼:
import logging
log = logging.getLogger('script_2.download')
def some_function():
log.debug('doing some_function')
我的輸出不會反映模塊登錄
2014-01-13 12:56:04,428 Script_2:DEBUG:Launching the meat of script_2
2014-01-13 12:56:05,005 Script_2:INFO:Script_2 completed successfully
什麼我錯過了嗎?直到我說的RotatingFileHandler ...
我試圖從論壇中與其他解決方案,包括Python logging over multiple files
但沒有骰子日誌模塊的工作就好了。任何幫助?