#!/usr/bin/python
import logging
import logging.handlers
def set_logger(filename, logmod):
log_size = 100000000
log_backupcount = 1
handler = logging.handlers.RotatingFileHandler(filename, maxBytes=log_size, backupCount=log_backupcount)
formatter = logging.Formatter("%(asctime)s %(levelname)s: %(message)s", datefmt='[%b %d %H:%M:%S]')
handler.setFormatter(formatter)
logger = logging.getLogger(logmod)
logger.setLevel(logging.INFO)
logger.addHandler(handler)
return logger
def get_logger(logmod):
logger = logging.getLogger(logmod)
return logger
【python】实用的logging封装
最新推荐文章于 2024-08-23 13:33:21 发布