Logging.py 1.39 KB
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import logging,os
# from mylog import mylogger,logg

 
class Logger():
 
    def __init__(self, path=__name__,clevel = logging.ERROR,Flevel = logging.DEBUG,test = 'w'):
        current_path=os.path.dirname(os.path.dirname(__file__))
        path=current_path+"/report"+"/test.log"
        # setattr(mylogger, "logpath", path)
        # logg.setting()
        
        self.logger = logging.getLogger(path)
        
        self.logger.setLevel(logging.DEBUG)
        
        fmt = logging.Formatter('[%(asctime)s] [%(levelname)s] : %(message)s', '%Y-%m-%d %H:%M:%S')
        
        sh = logging.StreamHandler()
        
        sh.setFormatter(fmt)
        
        sh.setLevel(clevel)
        
        #设置文件日志
        
        fh = logging.FileHandler(path,mode=test,encoding="utf-8")
        
        fh.setFormatter(fmt)
        
        fh.setLevel(Flevel)
        
        self.logger.addHandler(sh)
        
        self.logger.addHandler(fh)
    
    
    def debug(self,message):
        
        self.logger.debug(message)
    
    def info(self,message):
        
        self.logger.info(message)
    
    
    def warn(self,message):
    
        self.logger.warn(message)
    
    
    def error(self,message):
    
        self.logger.error(message)
    
    
    def critical(self,message):
    
        self.logger.critical(message)


log=Logger()