def wrapped(*args, **kwargs): """ This function does all the heavy-lifting of the function, setting the sys.setprofile to start for the function being called. Will check that the wrapper hasn't been called by a function that has called the current function Clear the data saved in func after done """ global Lock global Depth Depth += 1 if Lock == 1: try: # THIS *SHOULD BE* THE RETURN FROM THE FUNCTION JUST CALLED res = func(*args, **kwargs) except: res = None return res else: Lock = 1; # Start the Profiler sys.settrace(tracer) try: args2 = (args[1],) response = func(*args2, **kwargs) #response = func(*args, **kwargs) finally: # Stop the Profiler sys.settrace(None) # Build a hierarchy of all the frames calling one another func.frame_list.build_hierarchy() global Write_Called Write_Called += 1 # Print output to Logger res = func.frame_list.to_json_output( \ depth=depth, include_keys=include_keys, include_variables=include_variables, exclude_keys=exclude_keys, exclude_variables=exclude_variables) try: output_to_logger(res) except: # Something went wrong with the logger a = 10 # Reset Things func.frame_list = FrameList() Depth = 0 Lock = 0 return response
def test_log_simple_has_lead_in(self): from outlib.lib.wout import output_to_logger with LogCapture() as l: output_to_logger('This is a Test') assert '===============================================' in l.records[0].msg
def wrapped_f(*args,**kwargs): ''' settings = self.__dict__.copy() depth = settings.pop('_depth', 0) def callback(context, name, ob): config = context.config.with_package(info.module) config.add_view(view=ob, **settings) info = self.venusian.attach(wrapped, callback, category='pyramid', depth=depth + 1) if info.scope == 'class': # if the decorator was attached to a method in a class, or # otherwise executed at class scope, we need to set an # 'attr' into the settings if one isn't already in there if settings.get('attr') is None: settings['attr'] = wrapped.__name__ settings['_info'] = info.codeinfo # fbo "action_method" import pdb;pdb.set_trace() ''' global Depth Depth += 1 global Lock if Lock == 1: try: # THIS *SHOULD BE* THE RETURN FROM THE FUNCTION JUST CALLED res = func(*args, **kwargs) except: res = None return res else: Lock = 1; # Start the Profiler sys.settrace(tracer) try: args2 = (args[1],) response = wrapped(*args2, **kwargs) #response = wrapped(*args, **kwargs) finally: # Stop the Profiler sys.settrace(None) # Build a hierarchy of all the frames calling one another wrapped.frame_list.build_hierarchy() global Write_Called Write_Called += 1 # Print output to Logger res = wrapped.frame_list.to_json_output( \ depth=depth, include_keys=include_keys, include_variables=include_variables, exclude_keys=exclude_keys, exclude_variables=exclude_variables) try: output_to_logger(res) except: # Something went wrong with the logger a = 10 # Reset Things wrapped.frame_list = FrameList() Depth = 0 Lock = 0 return response return wrapped(*args)
def my_view(request): output_to_logger(format_value({'a': 'b'})) output_to_logger(value_to_json(format_value({'c': ['d', 1]}))) return {'project': 'outlib'}