def filter(self, record): try: relpath = get_rel_path(record.source_file) lineno = record.source_lineno except AttributeError: relpath = get_rel_path(record.pathname) lineno = record.lineno if lineno: record.source = "{}:{}".format(relpath, lineno) else: record.source = relpath return True
def filter(self, record): try: relpath = get_rel_path(record.source_file) or record.source_file lineno = record.source_lineno except AttributeError: relpath = get_rel_path(record.pathname) or record.pathname lineno = record.lineno if lineno: record.source = "%s:%d" % (relpath, lineno) else: record.source = relpath return True
def _showwarning(message, category, filename, lineno, file=None, line=None): relpath = get_rel_path(filename) if relpath: # Only show warnings from inside this project message = "%s from %s:%d: %s" % (category.__name__, relpath, lineno, message) logger.warning(message)
def _annote_failure(fail_message=""): # Inspect the stack with 1 line of context, looking at the 2nd frame # before this one, assuming the first frame is whatever called this function, # and the second frame is where the assertion failure took place frameinfo = inspect.getframeinfo(inspect.stack(1)[2][0]) if not fail_message: fail_message = str(frameinfo.code_context[0]).strip() filename = get_rel_path(frameinfo.filename) or frameinfo.filename path = "%s:%r" % (filename, frameinfo.lineno) return "%s (%s)" % (fail_message, path)
def _soft_assert_func(expr, fail_message=''): if not expr: # inspect the calling frame to find where the original assertion failed # explicitly requesting one line of code context so we can set fail_message if needed frameinfo = inspect.getframeinfo(inspect.stack(1)[1][0]) if not fail_message: fail_message = str(frameinfo.code_context[0]).strip() path = '%s:%r' % (get_rel_path(frameinfo.filename), frameinfo.lineno) fail_message = '%s (%s)' % (fail_message, path) _thread_locals.caught_asserts.append(fail_message)
def _annote_failure(fail_message=''): # Inspect the stack with 1 line of context, looking at the 2nd frame # before this one, assuming the first frame is whatever called this function, # and the second frame is where the assertion failure took place frameinfo = inspect.getframeinfo(inspect.stack(1)[2][0]) if not fail_message: fail_message = str(frameinfo.code_context[0]).strip() filename = get_rel_path(frameinfo.filename) or frameinfo.filename path = '%s:%r' % (filename, frameinfo.lineno) return '%s (%s)' % (fail_message, path)
def _showwarning(message, category, filename, lineno, file=None, line=None): relpath = get_rel_path(filename) if relpath: # Only show warnings from inside this project message = "{} from {}:{}: {}".format(category.__name__, relpath, lineno, message) try: logger.warning(message) except ImportError: # In case we have both credentials.eyaml and credentials.yaml, it gets in an import loop # Therefore it would raise ImportError for art_client. Let's don't bother and just spit # it out. This should reduce number of repeated questions down by 99%. print("[WARNING] {}".format(message))
def _annotate_failure(fail_message=''): # frames # 0: call to nth_frame_info # 1: _annotate_failure (this function) # 2: _annotate_failure caller (soft assert func or CM) # 3: failed assertion frameinfo = nth_frame_info(3) if not fail_message: fail_message = str(frameinfo.code_context[0]).strip() filename = get_rel_path(frameinfo.filename) path = '%s:%r' % (filename, frameinfo.lineno) return '%s (%s)' % (fail_message, path)
def _annotate_failure(fail_message=''): # frames # 0: call to nth_frame_info # 1: _annotate_failure (this function) # 2: _annotate_failure caller (soft assert func or CM) # 3: failed assertion frameinfo = nth_frame_info(3) if not fail_message: fail_message = str(frameinfo.code_context[0]).strip() filename = get_rel_path(frameinfo.filename) path = '{}:{!r}'.format(filename, frameinfo.lineno) return '{} ({})'.format(fail_message, path)
def process(self, msg, kwargs): # frames # 0: call to nth_frame_info # 1: adapter process method (this method) # 2: adapter logging method # 3: original logging call frameinfo = nth_frame_info(3) extra = kwargs.get('extra', {}) # add extra data if needed if not extra.get('source_file'): if frameinfo.filename: extra['source_file'] = get_rel_path(frameinfo.filename) extra['source_lineno'] = frameinfo.lineno else: # calling frame didn't have a filename extra['source_file'] = 'unknown' extra['source_lineno'] = 0 kwargs['extra'] = extra return msg, kwargs
def filter(self, record): record.pathname = get_rel_path(record.pathname) return True
def _showwarning(message, category, filename, lineno, file=None, line=None): relpath = get_rel_path(filename) if relpath: message = "{} from {}:{}: {}".format(category.__name__, relpath, lineno, message) logger.warning(message)