python之logging模块
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python之logging模块相关的知识,希望对你有一定的参考价值。
from logging import * import sys def main(): basicConfig(level=WARNING, stream=sys.stdout, # filename=‘log.log‘, # filemode=‘a‘, format=‘%(asctime)s\t%(filename)s\t%(lineno)d\t%(message)s\t%(levelname)s\t‘ ‘%(pathname)s\t%(module)s\t%(name)s\t%(funcName)s\t%(created)f\t‘ ‘%(relativeCreated)d\t%(thread)d\t%(threadName)s\t%(process)d‘, datefmt=‘%Y %m %d %H:%M:%S %a %b‘) debug(‘aaa debug‘) info(‘bbb info‘) warn(‘ccc warn‘) warning(‘ccc warning‘) error(‘ddd error‘) critical(‘critical‘) fatal(‘fatal‘) def main2(): format1 = ‘%(asctime)s\t%(filename)s\t%(lineno)d\t%(message)s\t%(levelname)s\t‘ ‘%(pathname)s\t%(module)s\t%(name)s\t%(funcName)s\t%(created)f\t‘ ‘%(relativeCreated)d\t%(thread)d\t%(threadName)s\t%(process)d‘ # basicConfig(level=WARNING, # stream=sys.stdout, # # filename=‘log.log‘, # # filemode=‘a‘, # format=format, # datefmt=‘%Y %m %d %H:%M:%S %a %b‘) logger = getLogger(‘xxx‘) logger.setLevel(DEBUG) stream_handler = StreamHandler() stream_handler.setLevel(DEBUG) file_handler = FileHandler(‘log2.log‘) file_handler.setLevel(DEBUG) formatter = Formatter(fmt=format1, datefmt=‘%Y %m %d %H:%M:%S %a %b‘) stream_handler.setFormatter(formatter) file_handler.setFormatter(formatter) logger.addHandler(stream_handler) logger.addHandler(file_handler) logger.debug(‘aaa debug‘) logger.info(‘bbb info‘) logger.warn(‘ccc warn‘) logger.warning(‘ccc warning‘) logger.error(‘ddd error‘) logger.critical(‘critical‘) logger.fatal(‘fatal‘) # main2() def main3(): error(‘llllllllll‘) main3() """ CRITICAL = 50 FATAL = CRITICAL ERROR = 40 WARNING = 30 WARN = WARNING INFO = 20 DEBUG = 10 NOTSET = 0 """
以上是关于python之logging模块的主要内容,如果未能解决你的问题,请参考以下文章