def detect_scopes():
scopes = []
current_frame = inspect.currentframe()
while current_frame is not None:
if current_frame.f_code.co_name == 'logging_scope':
scopes.append(current_frame.f_locals['name'])
else:
argvalues = inspect.getargvalues(current_frame)
if 'self' in argvalues.args and getattr(argvalues.locals['self'].__class__, 'AUTO_LOGGING_SCOPE',
False):
scopes.append(argvalues.locals['self'])
current_frame = current_frame.f_back
out_scopes = []
seen = set()
for scope in scopes[::-1]:
if scope not in seen:
out_scopes.append(scope if isinstance(scope, six.string_types) else (scope.name or scope.__class__.__name__))
seen.add(scope)
return out_scopes
评论列表
文章目录