【python】實用的logging封裝
阿新 • • 發佈:2018-03-15
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封裝