代码语言:javascript复制
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
# logName 日志中的某个格式化的字段名,logFile生成的日志文件名
def getlogger(logName, logFile):
logger=logging.getLogger(logName)
logger.setLevel(logging.DEBUG)
screenHandle = logging.StreamHandler()
screenHandle.setLevel(logging.DEBUG)
fileHandle = logging.FileHandler(logFile,'a')
fileHandle.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
screenHandle.setFormatter(formatter)
fileHandle.setFormatter(formatter)
logger.addHandler(fileHandle)
logger.addHandler(screenHandle)
return logger