Logging identifier name and value

I'm looking to have a function were I can pass some arguments and it would print the name of the identifier and the value (in string) of it.

With the folwing code, I work perfect when I am in the script console.

But when I try to attach this into a script so I can call it from anywhere, the namespace globals() does not hold the identifier name.

Any idea ?


foo1 = 1
foo2 = "22"
foo3 = ['333']


def printTags(*args):	
        #Return the name of an identifier
	def namestr(obj):
		namespace = globals()
		objName = [name for name in namespace if namespace[name] is obj]		
		return str(objName)	

	#iterate all the args to print the name of the identifier and the value	
	for i in range(0, len(args)):
		logInfo = namestr(args[i]) + ": " + str(args[i])		
		system.util.getLogger("Log").warn(logInfo) 
		print (logInfo) #used for debugging	
		
printTags(foo1, foo2, foo3)