You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.1 KiB
79 lines
2.1 KiB
|
|
import logging |
|
import sys |
|
|
|
|
|
def getLogger(is_debug): |
|
if (is_debug): |
|
logging.basicConfig(level=logging.DEBUG) |
|
|
|
logger = logging.getLogger(__name__) |
|
formatter = logging.Formatter( |
|
fmt='%(asctime)s, %(levelname)-5s [%(filename)s:%(lineno)d, %(funcName)s] %(message)s' |
|
) |
|
handler = logging.StreamHandler(sys.stdout) |
|
handler.setLevel(logging.DEBUG) |
|
handler.setFormatter(formatter) |
|
logger.addHandler(handler) |
|
|
|
return logger |
|
|
|
# NOTE: modified from here: https://code.activestate.com/recipes/137951-dump-all-the-attributes-of-an-object/ |
|
# to only print attributes |
|
def dumpObjAttr(obj): |
|
import types |
|
|
|
MethodWrapperType = type(object().__hash__) |
|
objclass = getattr(obj, '__class__') |
|
attrs = [] |
|
|
|
for slot in dir(obj): |
|
attr = getattr(obj, slot) |
|
if slot == '__class__': |
|
objclass = attr.__name__ |
|
elif slot == '__doc__': |
|
pass |
|
elif slot == '__module__': |
|
pass |
|
elif slot == '__dict__': |
|
pass |
|
elif slot == '__weakref__': |
|
pass |
|
elif (isinstance(attr, types.BuiltinMethodType) or |
|
isinstance(attr, MethodWrapperType)): |
|
pass |
|
elif (isinstance(attr, types.MethodType) or |
|
isinstance(attr, types.FunctionType)): |
|
pass |
|
else: |
|
attrs.append( (slot, attr) ) |
|
|
|
sOut = objclass + ':' |
|
for key, value in attrs: |
|
# NOTE: pretty print for long lists |
|
if isinstance(value, list) or isinstance(value, tuple): |
|
sOut += '\n\t' + key + ':' |
|
sOut += dumpList(value, 2) |
|
else: |
|
sOut += '\n\t' + key + ': ' + str(value) |
|
|
|
return sOut |
|
|
|
def dumpList(value, indent): |
|
s = '' |
|
if len(value) > 0: |
|
if isinstance(value[0], tuple): |
|
for k, v in value: |
|
s += '\n' + (indent * '\t') + k + ': ' + str(v) |
|
elif isinstance(value, list): |
|
for item in value: |
|
s += '\n' + (indent * '\t') + str(item) |
|
else: |
|
pass |
|
|
|
return s |
|
|
|
def getFunctionName(): |
|
import sys |
|
return sys._getframe(1).f_code.co_name |
|
|
|
|