日志模块应用:
import logging,time
from logging.handlers import TimedRotatingFileHandler
log = logging.getLogger("test")
log.setLevel(logging.DEBUG)
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
formatter = logging.Formatter(LOG_FORMAT)
handler = TimedRotatingFileHandler("aaa.txt", when="m", interval=1, backupCount=10, encoding='UTF-8')
handler.setFormatter(formatter)
log.addHandler(handler)
# logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
log.debug("This is a debug log.")
log.info("This is a info log.")
log.warning("This is a warning log.")
log.error("This is a error log.")
while(True):
time.sleep(1)
log.critical("This is a critical log.")