Пример #1
0
    def _log_method(self, context, args, kwargs):
        method = helpers.get_current_method(context)
        param_gen = itertools.chain(
            (six.text_type(arg) for arg in args),
            (u'{0} => {1}'.format(name, value)
             for name, value in six.iteritems(kwargs)))
        params_str = u', '.join(param_gen)
        method_name = '::'.join((method.declaring_type.name, method.name))
        thread_id = helpers.get_current_thread_id()
        caller_str = ''
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx is not None:
            frame = stack_trace.compose_stack_frame(caller_ctx)
            if frame['location']:
                caller_str = ' called from ' + stack_trace.format_frame(frame)

        LOG.trace(u'{thread}: Begin execution {method}({params}){caller}'
                  .format(thread=thread_id, method=method_name,
                          params=params_str, caller=caller_str))
        try:
            def log_result(result):
                LOG.trace(
                    u'{thread}: End execution {method} with result '
                    u'{result}'.format(
                        thread=thread_id, method=method_name, result=result))
            yield log_result
        except Exception as e:
            LOG.trace(
                u'{thread}: End execution {method} with exception '
                u'{exc}'.format(thread=thread_id, method=method_name, exc=e))
            raise
Пример #2
0
    def _log_method(self, context, args, kwargs):
        method = helpers.get_current_method(context)
        param_gen = itertools.chain(
            (six.text_type(arg) for arg in args),
            (u'{0} => {1}'.format(name, value)
             for name, value in kwargs.items()))
        params_str = u', '.join(param_gen)
        method_name = '::'.join((method.declaring_type.name, method.name))
        thread_id = helpers.get_current_thread_id()
        caller_str = ''
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx is not None:
            frame = stack_trace.compose_stack_frame(caller_ctx)
            if frame['location']:
                caller_str = ' called from ' + stack_trace.format_frame(frame)

        LOG.trace(u'{thread}: Begin execution {method}({params}){caller}'
                  .format(thread=thread_id, method=method_name,
                          params=params_str, caller=caller_str))
        try:
            def log_result(result):
                LOG.trace(
                    u'{thread}: End execution {method} with result '
                    u'{result}'.format(
                        thread=thread_id, method=method_name, result=result))
            yield log_result
        except Exception as e:
            LOG.trace(
                u'{thread}: End execution {method} with exception '
                u'{exc}'.format(thread=thread_id, method=method_name, exc=e))
            raise
Пример #3
0
def compose_stack_frame(context):
    instruction = helpers.get_current_instruction(context)
    return {
        'instruction': None if instruction is None else str(instruction),
        'location':
        None if instruction is None else instruction.source_file_position,
        'method': helpers.get_current_method(context),
        'class': helpers.get_type(context)
    }
Пример #4
0
def compose_stack_frame(context):
    instruction = helpers.get_current_instruction(context)
    method = helpers.get_current_method(context)
    return {
        'instruction': None if instruction is None else str(instruction),
        'location':
        None if instruction is None else instruction.source_file_position,
        'methodName': None if method is None else method.name,
        'typeName': None if method is None else method.declaring_type.name
    }
Пример #5
0
def compose_stack_frame(context):
    instruction = helpers.get_current_instruction(context)
    method = helpers.get_current_method(context)
    return {
        'instruction': None if instruction is None else unicode(instruction),
        'location':
        None if instruction is None else instruction.source_file_position,
        'method': None if method is None else method.name,
        'class': None if method is None else method.murano_class.name
    }
Пример #6
0
def compose_stack_frame(context):
    instruction = helpers.get_current_instruction(context)
    return {
        'instruction': None if instruction is None
        else str(instruction),

        'location': None if instruction is None
        else instruction.source_file_position,

        'method': helpers.get_current_method(context),
        'class': helpers.get_type(context)
    }
Пример #7
0
def compose_stack_frame(context):
    instruction = helpers.get_current_instruction(context)
    method = helpers.get_current_method(context)
    return {
        'instruction': None if instruction is None
        else six.text_type(instruction),

        'location': None if instruction is None
        else instruction.source_file_position,

        'methodName': None if method is None else method.name,
        'typeName': None if method is None else method.declaring_type.name
    }
Пример #8
0
def compose_stack_frame(context):
    instruction = helpers.get_current_instruction(context)
    method = helpers.get_current_method(context)
    return {
        'instruction': None if instruction is None
        else unicode(instruction),

        'location': None if instruction is None
        else instruction.source_file_position,

        'method': None if method is None else method.name,
        'class': None if method is None else method.murano_class.name
    }
Пример #9
0
    def initialize(self, _context, includeNativeFrames=True):
        frames = []
        context = _context
        while True:
            if not context:
                break
            instruction = helpers.get_current_instruction(context)
            frames.append({
                'instruction': None if instruction is None
                else str(instruction),

                'location': None if instruction is None
                else instruction.source_file_position,

                'method': helpers.get_current_method(context),
                'class': helpers.get_type(context)
            })
            context = helpers.get_caller_context(context)
        frames.pop()
        frames.reverse()

        if includeNativeFrames:
            class InstructionStub(object):
                def __init__(self, title, position):
                    self._title = title
                    self.source_file_position = position

                def __str__(self):
                    return self._title

            native_frames = []
            for frame in inspect.trace()[1:]:
                info = inspect.getframeinfo(frame[0])
                position = yaql_expression.YaqlExpressionFilePosition(
                    os.path.abspath(info.filename), info.lineno,
                    -1, -1, -1, -1, -1)
                instruction = InstructionStub(
                    info.code_context[0].strip(), position)
                method = info.function
                native_frames.append({
                    'instruction': instruction,
                    'method': method,
                    'class': None
                })
            frames.extend(native_frames)

        self.set_property('frames', frames)
Пример #10
0
    def initialize(self, _context, includeNativeFrames=True):
        frames = []
        context = _context
        while True:
            if not context:
                break
            instruction = helpers.get_current_instruction(context)
            frames.append({
                'instruction': None if instruction is None
                else str(instruction),

                'location': None if instruction is None
                else instruction.source_file_position,

                'method': helpers.get_current_method(context),
                'class': helpers.get_type(context)
            })
            context = helpers.get_caller_context(context)
        frames.pop()
        frames.reverse()

        if includeNativeFrames:
            native_frames = []
            for frame in inspect.trace()[1:]:
                location = yaql_expression.YaqlExpressionFilePosition(
                    os.path.abspath(frame[1]), frame[2],
                    -1, -1, -1, -1, -1)
                method = frame[3]
                native_frames.append({
                    'instruction': frame[4][0].strip(),
                    'location': location,
                    'method': method,
                    'class': None
                })
            frames.extend(native_frames)

        self.set_property('frames', frames)
Пример #11
0
    def _log_method(self, context, args, kwargs):
        method = helpers.get_current_method(context)
        param_gen = itertools.chain(
            (six.text_type(arg) for arg in args),
            (u"{0} => {1}".format(name, value) for name, value in six.iteritems(kwargs)),
        )
        params_str = u", ".join(param_gen)
        method_name = "{0}::{1}".format(method.murano_class.name, method.name)
        thread_id = helpers.get_current_thread_id()
        caller_str = ""
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx is not None:
            frame = stack_trace.compose_stack_frame(caller_ctx)
            if frame["location"]:
                caller_str = " called from " + stack_trace.format_frame(frame)

        LOG.trace(
            u"{thread}: Begin execution {method}({params}){caller}".format(
                thread=thread_id, method=method_name, params=params_str, caller=caller_str
            )
        )
        try:

            def log_result(result):
                LOG.trace(
                    u"{thread}: End execution {method} with result "
                    u"{result}".format(thread=thread_id, method=method_name, result=result)
                )

            yield log_result
        except Exception as e:
            LOG.trace(
                u"{thread}: End execution {method} with exception "
                u"{exc}".format(thread=thread_id, method=method_name, exc=e)
            )
            raise