log

 

 

def log(msg):
    # 创建一个logger
    logger = logging.getLogger('mylogger')
    logger.setLevel(logging.DEBUG)
    # 创建一个handler,用于写入日志文件
    fh = logging.FileHandler('tr_debug.log')
    fh.setLevel(logging.DEBUG)
    # 定义handler的输出格式
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    # 给logger添加handler
    logger.addHandler(fh)
    # 记录一条日志
    logger.info(msg)
    # 记录Traceback
    logging.basicConfig(filename='tr_debug.log',level=logging.DEBUG,)
    logging.exception('=======================exception=========================')

 

你可能感兴趣的:(log)