【python】实用的logging封装

#!/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
posted @ 2018-03-15 18:13  匡子语  阅读(356)  评论(0编辑  收藏  举报