1、实现python日志功能
2、只输出到文件,不输出到控制台
#encoding:utf-8 import logging from common import path_util logging_level=logging.INFO fileHandler = logging.FileHandler(path_util.get_abs_path("log","all.log")) fileHandler.setLevel(logging_level) formatter = logging.Formatter('%(asctime)s - %(levelname)s %(message)s') fileHandler.setFormatter(formatter) logger=logging.getLogger('') logger.addHandler(fileHandler) def __get_logger(): return logger def info(module_name,message): logger.info(get_msg(module_name,message)) def error(module_name,message): logger.error(get_msg(module_name,message)) def debug(module_name,message): logger.debug(get_msg(module_name,message)) def warn(module_name,message): logger.warn(get_msg(module_name,message)) def get_msg(module_name,message): return "[MODULE]:{module} :{msg}" .format(module=module_name,msg=message).decode("utf-8")