[英]Logger level is not set
我試圖從簡單的打印切換到正確的日志記錄。
我想使用兩個不同的記錄器,第一個在屏幕上顯示信息,另一個在文件中顯示。
我的問題是,即使我將處理程序級別設置為DEBUG,消息也只顯示在WARNING中。
以下是我的代碼示例:
def setup_logger(self):
"""
Configures our logger to save error messages
"""
# create logger for 'facemovie'
self.my_logger = logging.getLogger('FileLog')
# create file handler which logs even debug messages
fh = logging.FileHandler('log/fm.log')
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
self.console_logger = logging.getLogger('ConsoleLog')
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
#ch.setFormatter(formatter)
##Start logging in file
self.my_logger.info("######")
# add the handlers to the logger
self.my_logger.addHandler(fh)
self.console_logger.addHandler(ch)
# DEBUG
self.console_logger.info("MFCKR")
self.console_logger.debug("MFCKR")
self.console_logger.warning("MFCKR")
self.console_logger.error("MFCKR")
self.console_logger.critical("MFCKR")
self.my_logger.info("MFCKR")
self.my_logger.debug("MFCKR")
self.my_logger.warning("MFCKR")
self.my_logger.error("MFCKR")
self.my_logger.critical("MFCKR")
並輸出:
[jll@jll-VirtualBox:~/Documents/FaceMovie]$ python Facemoviefier.py -i data/inputs/samples -o data/
Selected profile is : frontal_face
MFCKR
MFCKR
MFCKR
Starting Application !
Output #0, avi, to 'data/output.avi':
Stream #0.0: Video: mpeg4, yuv420p, 652x498, q=2-31, 20780 kb/s, 90k tbn, 5 tbc
FaceMovie exited successfully!
[jll@jll-VirtualBox:~/Documents/FaceMovie]$ cat log/fm.log
2012-07-15 22:23:24,303 - FileLog - WARNING - MFCKR
2012-07-15 22:23:24,303 - FileLog - ERROR - MFCKR
2012-07-15 22:23:24,303 - FileLog - CRITICAL - MFCKR
我紅了文檔並在網上搜索了類似的錯誤,但找不到任何錯誤。
您是否有關於記錄器不顯示DEBUG和INFO的原因的想法?
謝謝 !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.