import logging # 创建logger实例 logger = logging.getLogger('example') logger.setLevel(logging.INFO) # 创建格式化器 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # 创建控制台处理器 console_handler = logging.StreamHandler() console_handler.setLevel(logging.DEBUG) console_handler.setFormatter(formatter) # 添加处理器到logger logger.addHandler(console_handler) # 输出日志消息 logger.debug('Debug message') logger.info('Info message') logger.warning('Warning message') logger.error('Error message') logger.critical('Critical message')
标签:格式化,console,handler,模块,logging,logger,message From: https://www.cnblogs.com/fuchenjie/p/17824864.html