# --author--=Michal # date=2019/8/21 import logging #################################### # 第一种方式:默认是直接控制台输出,也可以直接输出到文件中,2种只能选1 #################################### # logging.debug('debug logging') # logging.info("info logging") # logging.warning('warning logging') # logging.error("erro loggging") # logging.critical("critical logging") # logging.basicConfig( # level=logging.DEBUG, # format='%(asctime)s %(filename)s %(levelname)s %(message)s', # datefmt='%Y-%m-%d %H:%M:%S', # filename='logging.txt', # filemode='w' # ) # logging.debug('debug logging') # logging.info("info logging") # logging.warning('warning logging') # logging.error("erro loggging") # logging.critical("critical logging") #################################### # 第二种方式:既可以控制台输出,也可以文件输出 #################################### # 获取logger对象 logger = logging.getLogger() # 添加文件对象 fh = logging.FileHandler('logger.txt') # 添加控制台输出对象 ch = logging.StreamHandler() # 定义日志打印的格式 formatter = logging.Formatter('%(
来源:https://blog.csdn.net/weixin_42333583/article/details/100055477