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()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Android table布局開(kāi)發(fā)實(shí)現(xiàn)簡(jiǎn)單計(jì)算器2. 理解PHP5中static和const關(guān)鍵字3. jQuery 實(shí)現(xiàn)DOM元素拖拽交換位置的實(shí)例代碼4. php模擬實(shí)現(xiàn)斗地主發(fā)牌5. IntelliJ IDEA安裝插件的方法步驟6. phpstorm恢復(fù)默認(rèn)設(shè)置的方法步驟7. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)8. Python random庫(kù)使用方法及異常處理方案9. Vuex localStorage的具體使用10. .Net Core使用Coravel實(shí)現(xiàn)任務(wù)調(diào)度的完整步驟

網(wǎng)公網(wǎng)安備