Python日志器使用方法及原理解析
日志記錄,監(jiān)控,便于定位bug
進(jìn)行二次封裝
import osimport loggingfrom scripts.handle_yaml import do_yamlfrom scripts.handle_path import LOG_PATHclass HandleLog: def __init__(self, name=None): if name is None: self.my_logger = logging.getLogger('testcase') else: self.my_logger = logging.getLogger(name) self.my_logger.setLevel(do_yaml.get_data('log', 'logger_level')) console_handler = logging.StreamHandler() console_handler.setLevel('WARNING') log_filename = os.path.join(LOG_PATH, do_yaml.get_data('log', 'log_filename')) file_handler = logging.FileHandler(log_filename, encoding='utf-8') formater = logging.Formatter(’%(asctime)s - [%(levelname)s] - [msg]: %(message)s - %(name)s - %(lineno)d’) console_handler.setFormatter(formater) file_handler.setFormatter(formater) self.my_logger.addHandler(console_handler) self.my_logger.addHandler(file_handler) def get_logger(self): return self.my_loggerdo_log = HandleLog()
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Java類加載機(jī)制實(shí)現(xiàn)步驟解析2. python3實(shí)現(xiàn)往mysql中插入datetime類型的數(shù)據(jù)3. moment轉(zhuǎn)化時(shí)間戳出現(xiàn)Invalid Date的問題及解決4. python爬蟲實(shí)戰(zhàn)之制作屬于自己的一個(gè)IP代理模塊5. PHP如何打印跟蹤調(diào)試信息6. python如何實(shí)現(xiàn)word批量轉(zhuǎn)HTML7. ASP動(dòng)態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享8. ASP腳本組件實(shí)現(xiàn)服務(wù)器重啟9. ASP中if語句、select 、while循環(huán)的使用方法10. html小技巧之td,div標(biāo)簽里內(nèi)容不換行
