标签:for 创建 记录 name critical handle ctime logging encoding
import logginglogging.debug(‘这是一条debug, 开始使用日志啦‘)
logging.info(‘这是一条info, 开始使用日志啦‘)
logging.warning(‘这是一条warning, 开始使用日志啦‘)
logging.error(‘这是一条error, 开始使用日志啦‘)
logging.critical(‘这是一条critical告, 开始使用日志啦‘)
logging.basicConfig(level=logging.DEBUG, format=‘%(lineno)d - %(filename)s - %(asctime)s - %(name)s - %(levelname)s - %(message)s‘)
logger = logging.getLogger(name)
def my_log(logger_name=‘MY-LOG‘, log_file=‘de8ug.log‘, level=logging.DEBUG):
logger = logging.getLogger(logger_name)
logger.setLevel(level) # 添加等级
ch = logging.StreamHandler()
ch.setLevel(level)
fh = logging.FileHandler(filename=log_file, encoding=‘utf-8‘)
formatter = logging.Formatter(‘%(asctime)s %(filename)s [line:%(lineno)d] %(name)s %(levelname)s %(message)s‘)
ch.setFormatter(formatter)
fh.setFormatter(formatter)
logger.addHandler(ch)
logger.addHandler(fh)
return logger
标签:for 创建 记录 name critical handle ctime logging encoding
原文地址:http://blog.51cto.com/11212769/2133413