首页 > 编程语言 > 详细

python中的logging模块使用

时间:2020-07-31 17:28:46      阅读:81      评论:0      收藏:0      [点我收藏+]
#日志类
import os
import logging

current_path = os.path.dirname(__file__)
log_path = os.path.join(current_path, ‘../log/testpython.log‘)

class logUtil:
def __init__(self,logfile_path=log_path):
self.logfile_path=log_path
self.logger = logging.getLogger(‘log_util‘)
self.logger.setLevel(level=logging.INFO)
file_log = logging.FileHandler(log_path) # 闯将一个文件日志对象
formatter = logging.Formatter(‘%(asctime)s - %(name)s - %(levelname)s - %(message)s‘)
file_log.setFormatter(formatter)
self.logger.addHandler(file_log)


def info(self,message):
self.logger.info(message)

def error(self,errmessage):
self.logger.error(errmessage)

log_info=logUtil(log_path)

if __name__ == ‘__main__‘:
log=logUtil(log_path)
log.error(‘系统异常‘)
log.info(‘登录成功‘)

python中的logging模块使用

原文:https://www.cnblogs.com/tingting-yang/p/13410795.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!