log_formatter = logging.Formatter("%(asctime)s %(process)s %(thread)s %(filename)s [%(levelname)-5.5s] %(message)s")
TimedRotatingFileHandler 按照日期切分日誌python
以下:日誌
from logging.handlers import TimedRotatingFileHandler file_handler = TimedRotatingFileHandler('%smain.log' % log_path, when='midnight') file_handler.suffix = '%Y_%m_%d.log' file_handler.setFormatter(log_formatter)
StreamHandler std輸出code
以下:orm
std_handler = logging.StreamHandler(sys.stdout) std_handler.setFormatter(log_formatter)
logger = logging.getLogger() logger.addHandler(file_handler) logger.addHandler(std_handler) logger.setLevel(logging.WARNING)
終わり。