封装日志
作者:互联网
import logging
from logging import handlers
class Log_():
def __init__(self):
self.logger=logging.getLogger()
self.sh = logging.StreamHandler()
self.rh = handlers.RotatingFileHandler('myapp.log', maxBytes=1024, backupCount=3) # 按照大小做切割
self.fh = handlers.TimedRotatingFileHandler(filename='x2.log', when='s', interval=5, encoding='utf-8')
logging.basicConfig(
format='%(levelname)s - %(filename)s - %(asctime)s - %(name)s - [line :%(lineno)d] - [process :%(process)d] - [thread: %(thread)d] - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S %p',
level=logging.INFO,
handlers=[self.fh, self.rh]
)
logging.basicConfig(
format='%(levelname)s - %(filename)s - %(asctime)s - %(name)s - [line :%(lineno)d] - [process :%(process)d] - [thread: %(thread)d] - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S %p',
level=logging.ERROR,
handlers=[self.sh]
)
a=Log_().logger
标签:-%,logging,thread,handlers,process,self,封装,日志 来源: https://www.cnblogs.com/diracy/p/16079614.html