标签:hds handle logging ogg handler formatter line 位置 日志
‘‘‘
handler 名称:位置: 作用
StreamHandler: 日志输出到流
FIleHandler: 日志输出到文件
RotatingHandle: 日志回滚方式, 支持日志文件最大数量和日志文件回滚
‘‘‘
‘‘‘
logger = logging.getLogger(‘‘)
logger.setLevel(logging.INFO)
handler = logging.FileHandler(‘logs.txt‘)
handler.setLevel(logging.INFO)
formatter = logging.Formatter(‘%(asctime)s -%(levelname)s -%(lineno)d - %(message)s‘)
handler.setFormatter(formatter)
logger.addHandler(handler)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
logger.addHandler(console)
logger.info(‘test12334444444‘)
‘‘‘
‘‘‘
日志回滚
‘‘‘
logger = logging.getLogger(‘‘)
Rthandler = RotatingFileHandler(‘demo.txt‘, maxBytes=10*1024*1024, backupCount=3)
formatter = logging.Formatter(‘%(asctime)s -%(levelname)s -%(lineno)d - %(message)s‘)
Rthandler.setFormatter(formatter)
logger.addHandler(Rthandler)
logger.setLevel(logging.DEBUG)
logging.debug(‘dsfhsdjhfsdjhdsf‘)
标签:hds handle logging ogg handler formatter line 位置 日志
原文地址:https://www.cnblogs.com/xiaogao6681/p/11038244.html