封装日志

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


posted @ 2022-03-30 22:49  diracy  阅读(50)  评论(0编辑  收藏  举报