python 日志模块工具类

发布时间:2019-03-19 21:06:12编辑:auto阅读(2254)

    #!/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

     

关键字

上一篇: RHEL 6.6下Python 2.6.

下一篇: Python学习-变量