標籤:filename ogg bsp 檔案 and not python was inf
1 import logging 2 3 4 # 簡單列印日誌舉例 5 logging.basicConfig(level=logging.DEBUG) # 設定記錄層級,WARN 6 logging.warning(‘Watch out!‘) # will print a message to the console 7 logging.info(‘I told you so‘) # will not print anything 8 9 10 # 列印日誌到檔案,注意要新起一個檔案,否則不能儲存檔案11 def log_to_file(logs_dir="D:\\test_data\\logs\\log_DEBUG.txt"):12 logging.basicConfig(filename=logs_dir, level=logging.DEBUG)13 logging.debug(‘This message should go to the log file‘)14 logging.info(‘So should this‘)15 logging.warning(‘And this, too‘)16 17 18 log_to_file()19 20 # 多參數日誌21 logging.warning(‘%s before you %s‘, ‘Look‘, ‘leap!‘)22 23 # 日誌中列印時間24 logging.basicConfig(format=‘%(asctime)s %(message)s‘)25 logging.warning(‘is when this event was logged.‘)26 27 # 指定時間格式28 logging.basicConfig(format=‘%(asctime)s %(message)s‘, datefmt=‘%Y-%m-%d %I:%M:%S %p‘)29 logging.warning(‘is when this event was logged.‘)
注意:logging的參數設定只在第一次運行之前有效,只能設定一次,後續設定無效。
指定時間格式運行結果:
1 # 指定時間格式2 2017-08-12 10:47:07 PM is when this event was logged.
python之列印日誌logging