利用StreamHandler和FileHandler同时输出到控制台和文件
import logging
logger = logging.getLogger('Leung')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
sh = logging.FileHandler(filename=r'C:\Log\example.log')
sh.setLevel(logging.DEBUG)
logger.addHandler(ch)
logger.addHandler(sh)
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')