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


Python Logger.warn方法代码示例

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


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

示例1: __init__

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import warn [as 别名]
class PackageDictionary:
	##
	# Initialize a dictionary.
	##
	def __init__(self):
		self.dict={}
		self.log = Logger().get_instance(self)

	##
	# Verify whether the dictionary contains a given Package-name.
	##
	def hasKey(self, nsName):
		return (nsName in self.dict)

	##
	# Add a Package contained in the given sourceFile at the given line-nr
	# to the dictionary.
	#
	# @nsName - the name of the Package
	# @sourceFile - the name of the file in which the Package is declared
	#
	# @returns True/False indicating whether the Package was added
	##
	def add(self,sourceFile, nsName):
		isAdded = False

		if ( not(sourceFile in self.dict) ):
			self.dict[sourceFile] = nsName
			isAdded = True
		else:
			self.log.warn("Ignoring additional package declaration "+nsName+"for file ",\
							sourceFile+" already packaged in "+self.dict[sourceFile])

		return isAdded

	##
	# Retrieve a list of [sourceFile, lineNr] elements for which it holds
	# that in sourceFile at lineNr a class with name className is declared.
	#
	# @param className - the class name for which to find source locations.
	#
	# @returns a list of elements [sourceFile, lineNr]
	##
	def getPackageForFile(self, sourceFile):
		noNS = ""
		if ( sourceFile in self.dict ):
			return self.dict[sourceFile]
		else:
			return noNS
开发者ID:carvalhomb,项目名称:tsmells,代码行数:51,代码来源:javaDictionaries.py

示例2: handle

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import warn [as 别名]
	def handle(self):
		log = Logger().get_instance(self)
		f = xmlgen.Factory()
		data = self.request.recv(1024)
		try:
			[strategy,options] = data.split(":")
			log.info("Executing query: %s, %s" % (strategy, options))
			
			try:
				exec("import TrustStrategies.%s " % (strategy))
				exec("debug_module = (TrustStrategies.%s.%s.debug)" % (strategy, strategy))
				if debug_module:
					exec("reload(TrustStrategies.%s) " % (strategy))
				exec("tpf = TrustStrategies.%s.%s(self.server)" % (strategy, strategy))
				
			except (ImportError), i:
				from TrustStrategies.DefaultTPF import DefaultTPF
				tpf = DefaultTPF(self.server)
				log.warn("Caught ImportError: %s\nUsing DefaultTPF strategy." % (i))
			searchtime = time.time()
			r = tpf.query(options)
			searchtime = "%.6f" % (time.time() - searchtime)
			# build the xml response
			result = f.queryresult(r, executed="1", strategy=strategy, search_time=searchtime)
开发者ID:BackupTheBerlios,项目名称:konfidi-svn,代码行数:26,代码来源:QueryListener.py

示例3: MethodInvocationEntity

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import warn [as 别名]
class MethodInvocationEntity(Entity):
	uknDstMethods = []
	uknDstMethLoc = []
	uknDstTypes = []

	##
	# MSNPacket;getContent;mi;MSNProtocol;sendPacket;mi;p;000183;
	#								messenger/MSN/MSNProtocol.java;{};{IPacket}
	##
	def __init__(self, line):
		Entity.__init__(self, line)	# entity will initalize self.line and self.cols
		self.log = Logger().get_instance(self)
		self.cols = line.split(";")
		self.dst_class = self.cols[0]
		self.dst_name = self.cols[1]
		self.src_class = self.cols[3]
		self.src_name = self.cols[4]
		self.sourceFile = self.cols[8]
		self.lineNr = utils.removeUpfrontZeroes(self.cols[7])
		self.visibility = "public"
		self.src_param = utils.cleanCol(self.cols[10].strip()).split(",")
		self.dst_param = utils.cleanCol(self.cols[9]).split(",")
		# to be resolved later
		self.package = ""
		self.dst_package = ""
		self.srcLoc = ""
		self.srcLineNr = "0"
		self.dstLoc = ""
		self.dstLineNr = "0"
		#self.log.warn(self.cols[3]+"."+self.cols[4]+" -> "+self.cols[0]+"."+self.cols[1])

	def resolvePackage(self,pkgDict):
		self.package = pkgDict.getPackageForFile(self.sourceFile)
		return True

	def resolveOwner(self,mtdSrcDict):
		# for source method
		srcMtdSourceFiles = mtdSrcDict.getSourceLocFor(self.getSrcMethUniqName())
		# std. scenario
		if 1 == len(srcMtdSourceFiles):
			srcSourceFile = srcMtdSourceFiles[0].split(":")[0]
			srcStart = srcMtdSourceFiles[0].split(":")[1]

			self.srcLoc = srcSourceFile
			self.srcLineNr = srcStart
			return True
		elif 0 == len(srcMtdSourceFiles):
			self.log.warn(	"No sourceLocation for owner of method "+\
							self.getSrcMethUniqName())
			return False
		else:
			self.log.warn(	"Multiple sourceLocations for owner of method "+\
							self.getSrcMethUniqName()+": ",srcMtdSourceFiles)
			return False

	def resolveDestination(self,mtdDict,mtdSrcDict,classDict,pkgDict,impDict,inhDict):
		#self.log.warn("------------------------------------")
		#self.log.warn(self.cols[3]+"."+self.cols[4]+" -> "+self.cols[0]+"."+self.cols[1])

		dtr = InvocationDestinationResolver(mtdSrcDict,classDict,pkgDict,impDict,self)
		# destination type, destination method and destination location must
		# be known uniquely
		return 	dtr.resolveInvocationDstType() and \
				dtr.resolveDstMtd(mtdDict,inhDict) and \
				dtr.resolveDstMtdLoc(self.getDstMethUniqName())


	#def checkMethodsExist(self,inhDict, methDict):
	#	""" checks whether both src and dst methods are known to the model """
	#	return self.srcMethodExists(methDict) and self.dstMethodExists(inhDict, methDict)

	#def srcMethodExists(self, methDict):
	#	""" checks whether the src method is known to the model. \
	#		Haven't seen this failing up till now """
	#	srcSign = self.getSrcSignature()
	#	if not methDict.dictHasMethodInPackage(self.package,self.src_class,srcSign):
	#		srcMeth = self.getSrcMethUniqName()
	#		# library methods do not exist in the model, we don't report
	#		if self.__invokesLibraryMethod(): pass
	#		else: self.log.warn("Source method "+srcMeth+" not known")
	#		return False
	#	return True

	# Destination method resolution strategy methods





	def isMethodInvocation(self):
		if "mi" in self.cols[2] and "mi" in self.cols[5]: return True
		return False

	# all kind of getters

	def getOwnerUniqueName(self):
		if "" == self.package:
			return self.src_class
		else:
			return self.package + "::" + self.src_class
#.........这里部分代码省略.........
开发者ID:carvalhomb,项目名称:tsmells,代码行数:103,代码来源:javaEntities.py

示例4: __init__

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

	##
	#
	# e.g. AContact;fLogin;000040.016;messenger/AContact.java;40.22;0x1;{};{};{};{}
	##
	def __init__(self, line):
		""" Initialize a method entity given a line from the SourceNavigator \
			dbdump file (.methods). """
		self.log = Logger().get_instance(self)
		cols = line.split(";")
		self.owner = cols[0]
		self.name = cols[1]
		self.sourceFile = cols[3]
		self.lineNr = cols[4].split(".")[0]
		self.visibility = "public"
		# to be configured with additional information
		self.package = None
		self.attrType = None
		self.parentType = None

	def resolvePackage(self,pkgDict):
		self.package = pkgDict.getPackageForFile(self.sourceFile)

	def __locateAttributeType(self, pkgDict, classDict, attrType):
		""" identifies the source location of the attributes' type def."""
		if isPrimitiveType(attrType.resolvedName):
			# it is a primitive type, no source location for them
			attrType.resolvedName = ""
			attrType.sourceFile = ""
			attrType.lineNr = "0"
			self.attrType = attrType
			return

		# it is a class, but does the class dictionary know it?
		srcLocs = classDict.getSourceLocations(attrType.resolvedName)
		if 1 == len(srcLocs):
			dstLoc = srcLocs[0][0]
			dstLineNr = srcLocs[0][1]
			pkgName = pkgDict.getPackageForFile(dstLoc)
			attrType.resolvedName = \
					utils.composeQualifiedName(pkgName,attrType.resolvedName)
			attrType.sourceFile = dstLoc
			attrType.lineNr = dstLineNr
		elif 0 == len(srcLocs):
			# is it a library type? don't log about them
			if not isLibraryType(attrType.resolvedName):
				self.log.warn(	"no source locations for attribute type: "+\
								attrType.resolvedName+" of attribute "+\
								self.owner+"."+self.name)
			attrType.sourceFile = ""
			attrType.lineNr = "0"
		else:
			self.log.warn(	"multiple source locations (",srcLocs,\
							") for attribute type: "+\
							attrType.resolvedName+" of attribute "+self.owner+\
							"."+self.name)
			attrType.sourceFile = ""
			attrType.lineNr = "0"
		self.attrType = attrType

	def resolveAttrType(self, pkgDict, classDict, attrTypeDict):
		""" resolves attribute type information such as
			qualified name and source location """
		attrType = TypeReference()

		qualAttrName = self.getQualAttrName()
		if attrTypeDict.has_key(qualAttrName):
			attrType.referencedName = attrTypeDict[qualAttrName]
		else:
			attrType.referencedName = ""
		attrType.resolvedName = typeToClass(attrType.referencedName)
		self.__locateAttributeType(pkgDict, classDict, attrType)

	def resolveParentType(self,classDict):
		parentType = TypeReference()
		parentType.resolvedName = self.owner
		parentType.referencedName = \
						utils.composeQualifiedName(self.package,self.owner)
		self.parentType = parentType

		# TODO package!
		className = utils.spliceClass(	self.parentType.referencedName, \
										utils.qualSeparator)
		srcLocs = classDict.getSourceLocations(className)
		if 1 == len(srcLocs):
			dstLoc = srcLocs[0][0]
			dstLineNr = srcLocs[0][1]
			self.parentType.sourceFile = dstLoc
			self.parentType.lineNr = dstLineNr
			#pkgName = pkgDict.getPackageForFile(dstLoc)
			#attrType.resolvedName = \
			#		utils.composeQualifiedName(pkgName,attrType.resolvedName)
			#attrType.sourceFile = dstLoc
			#attrType.lineNr = dstLineNr
		elif 0 == len(srcLocs):
			self.log.warn(	"no source locations for attribute owner: "+\
							self.parentType.referencedName+" of attribute "+\
							self.owner+"."+self.name)
			self.parentType.sourceFile = ""
#.........这里部分代码省略.........
开发者ID:carvalhomb,项目名称:tsmells,代码行数:103,代码来源:javaEntities.py

示例5: __init__

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

    def __init__(self,pkgDict,impDict,inhDict, classDict,methDict,mtdSrcDict,miList, mtdpfDict, sFile,nr,content, raw):
        self.log = Logger().get_instance(self)
        self.pkgDict = pkgDict
        self.impDict = impDict
        self.inhDict = inhDict
        self.classDict = classDict
        self.methDict = methDict
        self.mtdSrcDict = mtdSrcDict
        self.miList = miList
        self.sourceFile = sFile
        self.lineNr = nr
        self.content = content
        self.raw = raw # full grep content
        self.mtdpfDict = mtdpfDict

        # to be filled in
        self.src_unqName = None # fully qualified caller method
        self.src_name = None    # caller method
        self.src_param = None   # caller method parameters

        self.dst_base = None
        self.dst_name = None
        self.dst_param = None

        self.srcLoc = None      # caller method filename
        self.srcLineNr = None   # caller method line number

        self.dstLoc = None
        self.dstLineNr = None

    def explore(self):
        """ First remove all useless or pre-existing candidates,
        then apply strict checking on remaining ones """
        #self.log.info("EXPLORING " + self.content)
        if self.__isMethodDef():
            self.log.warn("Method definition [" + self.content + "]")
            return False
        self.content = self.__cleanName()
        if "" == self.content:
            #self.log.warn("Empty content")
            return False
        if not self.__retrieveSourceMethod():
            self.log.warn("Failed to retrieve source method [" + self.content + "]")
            return False
        if not self.__uniqueDestination():
            self.log.warn("No unique destination [" + self.content + "]")
            return False
        if not self.__isExistingInvocation():
            return True

        # if self.__retrieveDstMethod():
        #     return True
        #self.log.warn("Existing invocation " + self.content)
        return False

    def __isMethodDef(self):
        """ calls on method def line are considered the def itself """
        mSrcLocs = self.mtdSrcDict.dict.values()
        srcLoc = [ self.sourceFile + ":" + self.lineNr ]
        return srcLoc in mSrcLocs

    def __cleanName(self):
        """ extract the identifier, e.g. "Blah._r483", before the ( """
        c = self.content
        name = ""
        i = len(c)-1
        if i < 0: return name
        while i >= 0:
            if c[i].isalnum() or "_" == c[i] or "." == c[i]:
                name = c[i] + name
                i = i - 1
            else:
                return name
        return name

    def __retrieveSourceMethod(self):
        """ retrieve the method definition with closest lineNr to the cand. """

        self.src_unqName, self.srcLineNr = self.mtdpfDict.getEnclosing(self.sourceFile, self.lineNr)
        if not self.src_unqName: return False
        #self.log.debug(">> srcMethod for " + self.content +" >> "+ self.src_unqName)
        self.src_name = self.src_unqName.split(".")[1].split("(")[0]
        signature = self.src_unqName.split("(")[1]
        self.src_param = signature[:len(signature)-1]
        self.srcLoc = self.sourceFile
        self.srcLineNr = str(self.srcLineNr)
        return True

    def __isExistingInvocation(self):
        """ Already an invocation with this name @ file:lineNr ? """
        #for j in self.miList:
        #    mi = j[0]

        #   unqName = mi[3] + "." + mi[4] + "(" + mi[5] + ")" # destination
        #    if self.sourceFile == mi[6] and self.lineNr == mi[7] and\
        #            self.dst_name in unqName:
                    #self.dst_name + self.dst_param in unqName:
        #        return True
#.........这里部分代码省略.........
开发者ID:carvalhomb,项目名称:tsmells,代码行数:103,代码来源:InsaneInvocationResolver.py

示例6: AnAccessibleEntity

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import warn [as 别名]
class AnAccessibleEntity(TypedEntity):
	def __init__(self, line):
		TypedEntity.__init__(self, line)
		self.log = Logger().get_instance(self)

		self.namespaceName = None

		self.cols = self.line.split(";")
		self.sourceIndicationIndex = -1 # to be initialized by subclass
		self.visibilityIndicationIndex = -1 # to be initialized by subclass
		self.nameIndex = -1 # to be initialized by subclass

		self.initialize()
		self.postInitialize() # for subclasses to override

	def initialize(self):
		self.initializeColsIndices()
		if self.cols != ['']:
			self.decomposeData()

	##
	# Initialize at least the following attributes:
	#	self.sourceIndicationIndex
	#	self.visibilityIndicationIndex
	#	self.nameIndex
	##
	def initializeColsIndices(self): abstract

	##
	# Provides an opportunity for subclasses to implement additional
	# initializations. E.g., initialization of additional attirbutes.
	##
	def postInitialize(self):
		pass

	##
	# Decomposes the entity line.
	#
	# @requires: self.cols to be initialized
	# @ensures: class, name and type of both source and destination to be initialized
	##
	def decomposeData(self):
		self.sourceFile = self.cols[self.sourceIndicationIndex]
		self.start = self.cols[self.sourceIndicationIndex+1].split(".")[0]
		self.end = self.start
		#self.sourceFile, self.start, self.end = returnSourceLocation(self.cols[self.sourceIndicationIndex])
		self.owner = ""
		declaredType = self.retrieveDeclaredType()
		typeReference = self.getTypeReference()
		typeReference.setReferencedName(declaredType)
		self.name = self.cols[self.nameIndex]
		self.decomposeVisibilityData()

	def retrieveDeclaredType(self):
		dbfields=self.cols[self.visibilityIndicationIndex+1:]
		contents = appendStringList(dbfields)

		if ( contents[0] != "{" ):
			self.log.error("Cannot deduce declared type from line.")
			return

		i = 1
		attrChars = []
		while contents[i] != "}":
			attrChars.append(contents[i])
			i = i + 1

		return self.cleanType(''.join(attrChars))


	def decomposeVisibilityData(self):
		vis = self.cols[self.visibilityIndicationIndex]

		if vis == "0x1":
			self.visibility = "private"
			self.hasClassScope = False
		elif vis == "0x2":
			self.visibility = "protected"
			self.hasClassScope = False
		elif vis == "0x4":
			self.visibility = "public"
			self.hasClassScope = False
		elif vis == "0x9":
			self.visibility = "private"
			self.hasClassScope = True
		elif vis == "0xa":
			self.visibility = "protected"
			self.hasClassScope = True
		elif vis == "0xc":
			self.visibility = "public"
			self.hasClassScope = True
		elif vis == "0x0": # constant global variables
			self.visibility = "public"
			self.hasClassScope = False
		else:
			typeReference = self.getTypeReference()
			self.log.warn( "Unknown visibility indicator for entity ",\
						typeReference.getReferencedName(),"::",self.name,": ",\
						vis)
			self.visibility = ""
#.........这里部分代码省略.........
开发者ID:carvalhomb,项目名称:tsmells,代码行数:103,代码来源:AccessibleEntities.py

示例7: __init__

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

#.........这里部分代码省略.........

		self.metricLOC, self.metricCC, self.metricCOM, \
		self.pkgName, self.className, self.methodName = \
			self.__decomposeCols(line)

		self.invEntRef = None # ref to invokable entity; to be resolved later
		self.log = Logger().get_instance(self)

	def __decomposeCols(self, line):
		# TODO: refactor this bogus implementation
		# ... and unit testit
		LOC=0
		CC=0
		COM=0
		uniqName = ""

		# grmbl! f... format
		i = 0

		# skip initial white spaces as long as id doesn't match max
		# number of possible id digits.
		while " " == line[i]:
			i = i + 1

		# skip id, doesn't interest us
		while " " != line[i]:
			i = i + 1

		# skip next batch of white spaces
		while " " == line[i]:
			i = i + 1

		while " " != line[i]:
			LOC = int(line[i]) + 10*LOC
			i = i + 1

		# skip next batch of white spaces
		while " " == line[i]:
			i = i + 1

		while " " != line[i]:
			CC = int(line[i]) + 10*CC
			i = i + 1

		# skip next batch of white spaces
		while " " == line[i]:
			i = i + 1

		while " " != line[i]:
			COM = int(line[i]) + 10*COM
			i = i + 1

		# skip next batch of white spaces
		while " " == line[i]:
			i = i + 1

		while i < len(line):
			uniqName = uniqName + line[i]
			i = i + 1

		# Abusing the utils function in this context where there is no
		# distinction between package, class and method separators.
		nrSeps = uniqName.count(self.sep)
		if nrSeps > 1: # there is a package
			pkgName = self.__extractPackage(uniqName)
			mtdName = uniqName[uniqName.rfind(self.sep)+1:]
			if "" == mtdName:
				# won't become a known entity
				return "","","","","",""
			classOwner = uniqName.split(pkgName)[1].split(mtdName)[0].replace(self.sep,"")
		elif 1 == nrSeps: # there is no package
			classOwner = uniqName.split(self.sep)[0]
			mtdName = uniqName.split(self.sep)[1]	
			pkgName = ""


		return str(LOC),str(CC),str(COM),pkgName,classOwner,mtdName

	def __extractPackage(self,uniqName):
		qClsName = uniqName[:uniqName.rfind(self.sep)]
		pkgName = qClsName[:qClsName.rfind(self.sep)]
		return pkgName

	def isKnownEntity(self, invEntDict):
		if not invEntDict.dictHasMethod(self.className,self.methodName):
			return False
		invEntWMatchingNames = \
					invEntDict.getMethodInClass(self.className, self.methodName)
		if 1 == len(invEntWMatchingNames):
			return True
		else:
			self.log.warn("multiple matches: ",invEntWMatchingNames)
			return False

	def composeUniqName(self):
		pkgName = self.pkgName.replace(self.sep,self.pkgSep)
		if "" == pkgName:
			return self.className+self.sep+self.methodName
		else:
			return pkgName+self.pkgSep+self.className+self.sep+self.methodName
开发者ID:carvalhomb,项目名称:tsmells,代码行数:104,代码来源:NCSSMetricEntity.py

示例8: __init__

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

#.........这里部分代码省略.........

		for declLoc in self.getDeclarationLocations():
			if not(declLoc in redeclarationLocations):
				tuples.append([declLoc])

		for defLoc in self.getDefinitionLocations():
			defFile = defLoc.getSourceFile()
			transIncludedFiles = transIncludeDict.getTransitiveIncludedFiles(defFile)

			associatedDeclarationLocations = []
			#self.log.warn("deffile: ",defFile)
			# by using only those declarations contained in tuples
			# we ensure that these are not redeclarations
			for atuple in tuples:
				#self.log.warn("curtuple: ",atuple)
				#self.log.warn("locs: ", str(associatedDeclarationLocations))

				declLoc = atuple[0]
				declFile = declLoc.getSourceFile()
				if declFile in transIncludedFiles:
					if not declLoc in associatedDeclarationLocations:
						#self.log.warn(" add")
						associatedDeclarationLocations.append(declLoc)
				elif transIncludeDict.foundConfidentSymlinkMatch(declFile, transIncludedFiles) and \
					not declLoc in associatedDeclarationLocations:
					#self.log.warn(" add after direct include")
					associatedDeclarationLocations.append(declLoc)
			#self.log.warn("locs after t processing: ", str(associatedDeclarationLocations))

			if len(associatedDeclarationLocations) == 0:
				## definition = declaration
				tuples.append([defLoc])
			elif len(associatedDeclarationLocations) > 1:
				self.log.warn(`len(associatedDeclarationLocations)` + " declarations found for definition.")
				#self.log.warn("		- ",associatedDeclarationLocations[0].sourceFile)
				#self.log.warn("		- ",associatedDeclarationLocations[1].sourceFile)
			else:
				singleDeclaration = associatedDeclarationLocations[0]
				for atuple in tuples:
					declLoc = atuple[0]
					if declLoc == singleDeclaration:
						atuple.append(defLoc)

		return tuples

	##
	# Filter out those tuples from self.getDeclarationDefinitionTuples(scope)
	# which do not contain a single location that is included by the
	# referencingSourceFile.
	##
	def getIncludedDeclarationDefinitionTuples(self, scope, referencingSourceFile):
		transIncludeDict = scope.getTransitiveIncludeDict()
		transIncludedFiles = transIncludeDict.getTransitiveIncludedFiles(referencingSourceFile)

		tuples = self.getDeclarationDefinitionTuples(scope)
		includedTuples = []
		for tuple in tuples:
			# verify whether at least one location is included by the reference
			for location in tuple:
				srcFile = location.getSourceFile()
				if srcFile in transIncludedFiles:
					includedTuples.append(tuple)
					break # process next tuple

		return includedTuples
开发者ID:carvalhomb,项目名称:tsmells,代码行数:69,代码来源:MultipleLocationEntity.py

示例9: __init__

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import warn [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

示例10: setup

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import warn [as 别名]
class AnnotationEntity:
	"""Parses annotation db line and tries to associate with 
		class or method in the neighbourhood"""
	##
	# /tmp/trunk/src/test/pacman/PacmanTest.java:30:	@Before public void setup() {
	##
	def __init__(self, line):
		self.log = Logger().get_instance(self)
		cols = line.split(":")
		self.sourceFile = cols[0].replace("./", "")
		self.lineNr = cols[1]
		self.content = cols[2].lstrip().split(" ")[0].strip() # typically some code behind it
		self.owner = ""
		
	def isValidAnnotation(self):
		if self.content.startswith("*") or \
			self.content.startswith("//") or \
			self.content.startswith("/*"): 
			return False
		return True
	
	def __getLocation(self):
		return self.sourceFile+":"+self.lineNr
			
	def findOwner(self, pkgDict, classDict, mtdpfDict, attrDict):
		#uniqueName = ""
		if self.__findClassOwner(pkgDict, classDict): 
			#print "classowner: ",self.owner
			return True
		elif self.__findMethodOwner(mtdpfDict): 
			#print "methodowner: ",self.owner
			return True
		# TODO annotations for attributes
		else:
			self.log.warn("Can not find owner for annotation: "+self.content+\
					 " on location: "+self.__getLocation())
		return False
	
	def __findClassOwner(self,pkgDict,classDict):
		resolved = False
		locClDict = classDict.createLocationBasedDictionary()
		
		loc = self.__getLocation()
		prevLoc = self.sourceFile+":"+str(int(self.lineNr)+1)
		
		# annotation typically resides on the line of the class itself
		# or above
		if loc in locClDict:
			self.owner = locClDict[loc][0]
			resolved = True
		elif prevLoc in locClDict:
			self.owner = locClDict[prevLoc][0]
			resolved = True
		
		if resolved:
			pkg = pkgDict.getPackageForFile(self.sourceFile)
			if pkg: 
				self.owner = pkg + "::" + self.owner
			return True
		else:
			return False
	
	def __findMethodOwner(self,mtdpfDict):
		#print mtdpfDict.dict.keys()
		#print self.sourceFile
		if not mtdpfDict.hasKey(self.sourceFile): return False
		
		mtdInSf = mtdpfDict.dict[self.sourceFile]
		for name, mtdLineNr in mtdInSf:
			annLineNr = int(self.lineNr)
			if 	mtdLineNr == annLineNr or \
				mtdLineNr == annLineNr+1:
				self.owner = name
				return True
		return False
开发者ID:carvalhomb,项目名称:tsmells,代码行数:77,代码来源:javaEntities.py

示例11: __init__

# 需要导入模块: from log4py import Logger [as 别名]
# 或者: from log4py.Logger import warn [as 别名]
class InvocationDestinationResolver:
    def __init__(self, mtdSrcDict, classDict, pkgDict, impDict, mtdInv):
        self.mtdSrcDict = mtdSrcDict
        self.classDict = classDict
        self.pkgDict = pkgDict
        self.impDict = impDict
        self.mtdInv = mtdInv
        self.log = Logger().get_instance(self)

    def resolveInvocationDstType(self):
        if self.mtdInv.dst_class in self.mtdInv.uknDstTypes:
            return
        isTypeResolved = False

        srcLocs = self.classDict.getSourceLocations(self.mtdInv.dst_class)
        if 1 == len(srcLocs):  # best case
            dstTypeLoc = srcLocs[0][0]
            self.__resolveSingleType(dstTypeLoc)
            isTypeResolved = True
        elif 0 == len(srcLocs):  # worst case, no solution
            self.__resolveNoType()
            isTypeResolved = False
        else:  # digg deeper (e.g. imports)
            isTypeResolved = self.__resolveMultipleTypes(srcLocs)
        return isTypeResolved  # look, I wrote a method with a single exit point!

    def __resolveSingleType(self, dstTypeLoc):
        # resolved as there is only one possible location
        pkgName = self.pkgDict.getPackageForFile(dstTypeLoc)
        self.mtdInv.dst_package = pkgName

    def __resolveNoType(self):
        # can't resolve, there is not a single possible location
        self.log.warn("URMI (MITYP): Can't find srcLoc for dst type: " + self.mtdInv.dst_class)
        self.mtdInv.uknDstTypes.append(self.mtdInv.dst_class)

    def __resolveMultipleTypes(self, srcLocs):
        # There are multiple locations, we should take packaging and
        # imports into account now
        for dstLoc in srcLocs:
            # we traverse the list of possible destination source files
            i = dstLoc[0]
            pkgName = self.pkgDict.getPackageForFile(i)
            uniqName = pkgName + common.utils.getPkgSeparator() + self.mtdInv.dst_class

            # We assume that there are no two suitable imports, and that
            # as soon as we find a matching solution, we take it, either
            # because the classes of source and destination match,
            # because the packages of the source file and the possible
            # destination file match or because there is a matching import
            # in the source file with the possible destination.
            #
            # Threats:
            # - we can wrongly conclude that matching class names means that
            #   source and destination are the same
            if self.mtdInv.src_class == self.mtdInv.dst_class:
                # STR1: source and destination class have same name
                self.mtdInv.dst_package = self.mtdInv.package
                return True
            if self.mtdInv.package == pkgName:
                # STR2: source and destination reside in the same package
                self.mtdInv.dst_package = self.mtdInv.package
                return True
            if not self.impDict.hasKey(self.mtdInv.srcLoc):
                # can't go to STR3 if info not present in impDict
                continue
            if self.impDict.hasImportFor(self.mtdInv.srcLoc, uniqName):
                # STR3: we found a destination source file with matching
                # import in the source source file.
                self.mtdInv.dst_package = pkgName
                return True
                # no solution yet, proceed to the next
                # none of the resolution strategies worked ...
        self.log.warn(
            "URMI (MITYP): none of multiple locations for dst class matched: " + self.mtdInv.dst_class + ":", srcLocs
        )
        return False

    def resolveDstMtd(self, mtdDict, inhDict):
        """ checks whether the dst method is known to the model. If not,\
			try a couple of resolution strategies before giving up """
        exists = False
        dstSign = self.mtdInv.getDstSignature()
        dstMeth = self.mtdInv.getDstMethUniqName()
        if "assertEquals" in dstMeth:
            return False  # let insane handle this, does a better job then SN

            # we already went through the resolution strategies. Give up
        if dstMeth in self.mtdInv.uknDstMethods:
            return False

        if not mtdDict.dictHasMethodInPackage(self.mtdInv.dst_package, self.mtdInv.dst_class, dstSign):
            # Uh oh ... dst method is not known to the model...
            # Therefore, we try a couple of resolution strategies.
            signature = java.javaEntities.stringSignature(self.mtdInv.dst_param)
            # 1) is it a library method? won't not exist, nor do we report
            if self.__invokesLibraryMethod():
                pass
            # 2) does it qualify for the SN lost parameter syndrome?
            elif self.__resolvedDstViaSNDeficiencyResolution(mtdDict, signature):
#.........这里部分代码省略.........
开发者ID:carvalhomb,项目名称:tsmells,代码行数:103,代码来源:InvocationDestinationResolver.py


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