python-logging工具
def Logger(**kwargs):
level = kwargs.pop('level', None)
filename = kwargs.pop('filename', None)
datefmt = kwargs.pop('datefmt', None)
format = kwargs.pop('format', None)
if level is None:
level = logging.DEBUG
if filename is None:
filename = 'default.log'
if datefmt is None:
datefmt = '%Y-%m-%d %H:%M:%S'
if format is None:
format = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
log = logging.getLogger(filename)
format_str = logging.Formatter(format, datefmt)
th = handlers.TimedRotatingFileHandler(filename=filename, when='D', backupCount=10000, encoding='utf-8')
th.setFormatter(format_str)
th.setLevel(logging.INFO)
log.addHandler(th)
log.setLevel(level)
return log