1. 程式人生 > >【python】實用的logging封裝

【python】實用的logging封裝

bin python ctime mes -m pytho efm form ati

#!/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封裝