code: def format(self, record):
      # safety guard if None was provided
      if record.msg is None:
          record.msg = ""
      else:
          # to avoid our logger puking on receiving exception instances etc.
          # .getMessage, used to interpolate it, would cast it to str anyways
          # and thus not puke
          record.msg = str(record.msg)
      if record.msg.startswith("| "):
          # If we already log smth which supposed to go without formatting, like
          # output for running a command, just return the message and be done
          return record.msg
  
      levelname = record.levelname
  
      if self.use_color and levelname in colors.LOG_LEVEL_COLORS:
          record.levelname = colors.color_word(
              "{:7}".format(levelname),
              colors.LOG_LEVEL_COLORS[levelname],
              force=True,
          )
      record.msg = record.msg.replace("\n", "\n| ")
      if self._tb:
          if not getattr(record, "notraceback", False):
              record.msg = self._tb() + "  " + record.msg
      if self._mem:
          record.msg = "%s %s" % (self._mem(), record.msg)
  
      return logging.Formatter.format(self, record)
  
imports: from contextlib import contextmanager
  from functools import partial
  import inspect
  import logging
  import os
  import sys
  import platform
  import random
  import logging.handlers
  import warnings
  from os.path import basename, dirname
  from collections import defaultdict
  from .utils import is_interactive, optional_args
  from .support import ansi_colors
label_desc: Use image node_id 3 for calling the ColorFormatter obj's underlying member method code with example usage: obj.format(record) and returns: logging, record