def formatted_str(self, colorized=True): """Return a formatted colorized line. This returns a line like qute without --json-logging would produce. Args: colorized: If True, ANSI color codes will be embedded. """ r = logging.LogRecord(self.category, self.loglevel, '', self.line, self.message, (), None) # Patch some attributes of the LogRecord if self.line is None: r.line = 0 r.created = self.timestamp.timestamp() r.module = self.module r.funcName = self.function formatter = log.ColoredFormatter(log.EXTENDED_FMT, log.DATEFMT, '{', use_colors=colorized) result = formatter.format(r) # Manually append the stringified traceback if one is present if self.traceback is not None: result += '\n' + self.traceback return result
def formatted_str(self, colorized=True): """Return a formatted colorized line. This returns a line like qute without --json-logging would produce. Args: colorized: If True, ANSI color codes will be embedded. """ r = logging.LogRecord(self.category, self.loglevel, '', self.line, self.message, (), None) # Patch some attributes of the LogRecord if self.line is None: r.line = 0 r.created = self.timestamp.timestamp() r.msecs = self.msecs r.module = self.module r.funcName = self.function format_str = log.EXTENDED_FMT format_str = format_str.replace('{asctime:8}', '{asctime:8}.{msecs:03.0f}') # Mark expected errors with (expected) so it's less confusing for tests # which expect errors but fail due to other errors. if self.expected and self.loglevel > logging.INFO: new_color = '{' + log.LOG_COLORS['DEBUG'] + '}' format_str = format_str.replace('{log_color}', new_color) format_str = re.sub( r'{levelname:(\d*)}', # Leave away the padding because (expected) is # longer anyway. r'{levelname} (expected)', format_str) formatter = log.ColoredFormatter(format_str, log.DATEFMT, '{', use_colors=colorized) result = formatter.format(r) # Manually append the stringified traceback if one is present if self.traceback is not None: result += '\n' + self.traceback return result