def create_logger(app_name, logfilename=None, level=logging.INFO,
console=False, syslog=False):
""" Build and return a custom logger. Accepts the application name,
log filename, loglevel and console logging toggle and syslog toggle """
log=logging.getLogger(app_name)
log.setLevel(logging.DEBUG)
# Add file handler
if logfilename != None:
log.addHandler(logging.FileHandler(logfilename))
if syslog:
log.addHandler(logging.handlers.SysLogHandler(address='/dev/log'))
if console:
log.addHandler(logging.StreamHandler())
# Add formatter
for handle in log.handlers:
formatter = logging.Formatter('%(asctime)s : %(levelname)-8s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
handle.setFormatter(formatter)
return log
custom_logger.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录