Go to the documentation of this file.00001 import sys
00002
00003 printPath = False
00004
00005 def getClassName( f ):
00006 try:
00007
00008 selfClass = f.f_locals[ 'self' ].__class__
00009 try:
00010
00011 mro = selfClass.__mro__
00012 except AttributeError:
00013 stack = [selfClass]
00014 mro = []
00015 while stack:
00016 curr = stack.pop(0)
00017 mro.append(curr)
00018 stack += curr.__bases__
00019
00020 funcName = f.f_code.co_name
00021 for c in mro:
00022 try:
00023
00024 if funcName.startswith( '__' ):
00025 method = c.__dict__[ '_' + c.__name__ + funcName ]
00026 else:
00027 method = c.__dict__[ funcName ]
00028 if method.func_code == f.f_code:
00029 return c.__name__ + '.'
00030 except KeyError:
00031 pass
00032 except:
00033 pass
00034
00035
00036 return ""
00037
00038 def printMessage( prefix, args, printPath ):
00039 f = sys._getframe(2)
00040 if printPath:
00041 print f.f_code.co_filename + "(" + str(f.f_lineno) + ") :"
00042 print prefix, getClassName( f ) + f.f_code.co_name + ':',
00043 for m in args:
00044 print m,
00045 print
00046
00047 def TRACE_MSG( *args ): printMessage( "Trace:", args, printPath )
00048 def DEBUG_MSG( *args ): printMessage( "Debug:", args, printPath )
00049 def INFO_MSG( *args ): printMessage( "Info:", args, printPath )
00050 def NOTICE_MSG( *args ): printMessage( "Notice:", args, printPath )
00051 def WARNING_MSG( *args ): printMessage( "Warning:", args, True )
00052 def ERROR_MSG( *args ): printMessage( "Error:", args, True )
00053 def CRITICAL_MSG( *args ): printMessage( "Critical:", args, True )
00054 def HACK_MSG( *args ): printMessage( "Hack:", args, True )
00055
00056