当前位置: 首页>>代码示例>>Python>>正文


Python Logger.set_loglevel方法代码示例

本文整理汇总了Python中log4py.Logger.set_loglevel方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.set_loglevel方法的具体用法?Python Logger.set_loglevel怎么用?Python Logger.set_loglevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在log4py.Logger的用法示例。


在下文中一共展示了Logger.set_loglevel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import set_loglevel [as 别名]
class ResolutionReport:
    ##
    # Initialize the generic data.
    ##
    def __init__(self, line):
        self.line = line.strip()
        self.entityType = "Undefined"
        self.logger = Logger().get_instance(self)
        self.logger.set_loglevel(LOGLEVEL_DEBUG)

        ##
        # Return a string representation of the report.
        ##

    def __repr__(self):
        assert False, "Should be implemented by subclass."

        ##
        # Verify whether the resolution succeeded.
        ##

    def resolutionSucceeded(self):
        assert False, "Should be implemented by subclass."

    def log(self):
        self.logger.debug("Failed to resolve " + self.entityType + ": " + self.line)
        self.logger.debug(self.__repr__())

    def logIfFlawed(self):
        if self.resolutionFeasible() and (not self.resolutionSucceeded()):
            self.log()
开发者ID:carvalhomb,项目名称:tsmells,代码行数:33,代码来源:__init__.py

示例2: __init__

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import set_loglevel [as 别名]
class LoggingProducerUtils:
    
    def __init__(self,parameterContainer, logLevel=log4py.LOGLEVEL_DEBUG, logTarget=LOGGER_PRODUCER_LOG_DIR):
        
        if parameterContainer.getParamValue(PRINTER_TYPE) is not None:
            self.__errorFileName = "%s" % (parameterContainer.getErrorFileName())
            self.__logFileName = "%s/%s-%s.log" % (parameterContainer.getParamValue(TMP_DIR),parameterContainer.getParamValue(PRINTER_TYPE), parameterContainer.getParamValue(PRINTER_NAME))
        else:
            if parameterContainer.getParamValue(PARAM_DIR) is not None:
                if os.access(parameterContainer.getFullPathJobDir(), os.W_OK) :
                    # Error/Log directory locally
                    self.__errorFileName = "%s/%s" % (parameterContainer.getFullPathJobDir(), parameterContainer.getErrorFileName())
                    self.__logFileName = "%s/%s.log" % (parameterContainer.getFullPathJobDir(), parameterContainer.getJobID())
                else:
                    # Error/Log directory remotely
                    self.__errorFileName = "%s/%s" % (parameterContainer.getInputDir(), parameterContainer.getErrorFileName())
                    self.__logFileName = "%s/%s.log" % (parameterContainer.getInputDir(), parameterContainer.getJobID())
            else:
                self.__errorFileName = "%s/%s" % (LOG_DIRECTORY, parameterContainer.getErrorFileName())
                self.__logFileName = "%s/%s.log" % (LOG_DIRECTORY, parameterContainer.getJobID())
        
        ### LOG4PY ###
        self._log4py = Logger().get_instance(self)
        self._jobid = parameterContainer.getJobID()
        
        # Set target(s) according to configuration
        if logTarget == LOGGER_JOBS_DIR and self.__logFileName is not None:
            self.__log4pyFile = self.__logFileName
        else:
            # Log to the producer log directory using the OsEnv variable from producerjavastarter.py
            #self.__log4pyFile = '/prod_data/sefas/data/traffic/log/producer_log4py_' + self.getLogFileTimestamp() +'.log'
            self.__log4pyFile = LOG_DIRECTORY+'/producer_log4py_' + self.getLogFileTimestamp() +'.log'
            
        self._log4py.set_target(self.__log4pyFile)
        
        # Set time format
        timeformat = "%Y-%m-%d %H:%M:%S "
        self._log4py.set_time_format(timeformat)
        # Set log format
        self._log4py.set_formatstring(FMT_SEFAS)
        # Set level from configuration file?
        self._log4py.set_loglevel(logLevel)
        # Set rotation
        self._log4py.set_rotation(log4py.ROTATE_DAILY)
        ### END LOG4PY ###
    
    def getLogFileTimestamp(self):
        t = datetime.datetime.now();
        return t.strftime("%Y%m%d")
    
    # Wrap the log4py methods  
    def info(self, msg):
        if self._jobid is not None:
            self._log4py.info("[JOB_ID=" + self._jobid + "] %s" % msg)
        else:
            self._log4py.info("[NO JOB_ID] %s" % msg)
        
    def error(self, msg, exceptionType=None, exceptionValue=None):
        self._log4py.set_target(self.__errorFileName)
        if self._jobid is not None:
            self._log4py.error("[JOB_ID=" + self._jobid +  "] %s" % msg)
        else:
            self._log4py.error("[NO JOB_ID] %s" % msg)
        if exceptionType != None and exceptionValue != None:
            type, values, tb = sys.exc_info()
            traceback.print_exception(exceptionType, exceptionValue, tb)
            if self._jobid is not None:
                self._log4py.error("[JOB_ID=" + self._jobid + "] %s" % tb)
            else:
                self._log4py.error("[NO JOB_ID] %s" % tb)
        
        # Finally write to regular log
        self._log4py.set_target(self.__log4pyFile)
        self._log4py.error(msg)
        
    def debug(self, msg):
        if self._jobid is not None:
            self._log4py.debug("[JOB_ID=" + self._jobid + "] %s" % msg)
        else:
            self._log4py.debug("[NO JOB_ID] %s" % msg)
        
    def warn(self, msg):
        if self._jobid is not None:
            self._log4py.warn("[JOB_ID=" + self._jobid + "] %s" % msg)
        else:
            self._log4py.warn("[NO JOB_ID=] %s" % msg)
        
    def getFormatString(self):
        self._log4py.get_formatstring()
        
    def setFormatString(self, format):
        self._log4py.set_formatstring(format)
        
    # Wrap the loglevel and target
    def setLogLevel(self, level):
        self._log4py.set_loglevel(level)
        
    def setLogTarget(self, target):
        self._log4py.set_target(target)
    
#.........这里部分代码省略.........
开发者ID:duhicomp,项目名称:workspace,代码行数:103,代码来源:LoggingProducerUtils.py

示例3: parsePmcmetrics

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import set_loglevel [as 别名]


# metrics and co

def parsePmcmetrics(pmcDb, invEntDict):
	from common.metrics  import	PmcMetricEntity
	
	timer = Timer("Parsing measurements")
	timer.start()
	nrOfMeasurements=0
	for line in open(pmcDb, "r"):
		pmcEnt = PmcMetricEntity(line)
		if not pmcEnt.isKnownEntity(invEntDict):
			continue
		
		uniqName = pmcEnt.invEntRef.getUniqueName()
		
		sLoc = SourceLocation(pmcEnt.filename, pmcEnt.lineNr, pmcEnt.lineNr)
		common.famix.cdifWriter.generateMetrics("CC", pmcEnt.metricCC, uniqName, sLoc)
		common.famix.cdifWriter.generateMetrics("NOS", pmcEnt.metricNOS, uniqName, sLoc)
		#common.famix.cdifWriter.generateMetrics("LOC", pmcEnt.metricLOC, uniqName, sLoc)
		common.famix.cdifWriter.generateMetrics("LOC", pmcEnt.metricNOS, uniqName, sLoc)
		nrOfMeasurements += 1

	timer.stop()
	timer.log(nrOfMeasurements)

log = Logger().get_instance()
log.set_loglevel(LOGLEVEL_DEBUG)
开发者ID:carvalhomb,项目名称:tsmells,代码行数:31,代码来源:snavTableReader.py


注:本文中的log4py.Logger.set_loglevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。