class_docstr: Log formatter used in Tornado.
  
  Key features of this formatter are:
  
  * Color support when logging to a terminal that supports it.
  * Timestamps on every log line.
  * Robust against str/bytes encoding problems.
  
  This formatter is enabled automatically by
  `tornado.options.parse_command_line` or `tornado.options.parse_config_file`
  (unless ``--logging=none`` is used).
  
  Color support on Windows versions that do not support ANSI color codes is
  enabled by use of the colorama__ library. Applications that wish to use
  this must first initialize colorama with a call to ``colorama.init``.
  See the colorama documentation for details.
  
  __ https://pypi.python.org/pypi/colorama
  
  .. versionchanged:: 4.5
     Added support for ``colorama``. Changed the constructor
     signature to be compatible with `logging.config.dictConfig`.
class_docstr_tok: ["Log","formatter","used","in","Tornado",".","Key","features","of","this","formatter","are",":","*","Color","support","when","logging","to","a","terminal","that","supports","it",".","*","Timestamps","on","every","log","line",".","*","Robust","against","str\/bytes","encoding","problems",".","This","formatter","is","enabled","automatically","by","`","tornado.options.parse_command_line","`","or","`","tornado.options.parse_config_file","`","(","unless","``","--","logging=none","``","is","used",")",".","Color","support","on","Windows","versions","that","do","not","support","ANSI","color","codes","is","enabled","by","use","of","the","colorama__","library",".","Applications","that","wish","to","use","this","must","first","initialize","colorama","with","a","call","to","``","colorama.init","``",".","See","the","colorama","documentation","for","details",".","__","https",":","\/\/pypi.python.org\/pypi\/colorama","..","versionchanged",":",":","4.5","Added","support","for","``","colorama","``",".","Changed","the","constructor","signature","to","be","compatible","with","`","logging.config.dictConfig","`","."]
code: def format(self, record: Any) -> str:
      try:
          message = record.getMessage()
          assert isinstance(
              message, basestring_type
          )  # guaranteed by logging
          # Encoding notes:  The logging module prefers to work with character
          # strings, but only enforces that log messages are instances of
          # basestring.  In python 2, non-ascii bytestrings will make
          # their way through the logging framework until they blow up with
          # an unhelpful decoding error (with this formatter it happens
          # when we attach the prefix, but there are other opportunities for
          # exceptions further along in the framework).
          #
          # If a byte string makes it this far, convert it to unicode to
          # ensure it will make it out to the logs.  Use repr() as a fallback
          # to ensure that all byte strings can be converted successfully,
          # but don't do it by default so we don't add extra quotes to ascii
          # bytestrings.  This is a bit of a hacky place to do this, but
          # it's worth it since the encoding errors that would otherwise
          # result are so useless (and tornado is fond of using utf8-encoded
          # byte strings wherever possible).
          record.message = _safe_unicode(message)
      except Exception as e:
          record.message = "Bad message (%r): %r" % (e, record.__dict__)
  
      record.asctime = self.formatTime(record, cast(str, self.datefmt))
  
      if record.levelno in self._colors:
          record.color = self._colors[record.levelno]
          record.end_color = self._normal
      else:
          record.color = record.end_color = ""
  
      formatted = self._fmt % record.__dict__
  
      if record.exc_info:
          if not record.exc_text:
              record.exc_text = self.formatException(record.exc_info)
      if record.exc_text:
          # exc_text contains multiple lines.  We need to _safe_unicode
          # each line separately so that non-utf8 bytes don't cause
          # all the newlines to turn into '\n'.
          lines = [formatted.rstrip()]
          lines.extend(
              _safe_unicode(ln) for ln in record.exc_text.split("\n")
          )
          formatted = "\n".join(lines)
      return formatted.replace("\n", "\n    ")
  
file_path: catboost/contrib/python/tornado/tornado-6/tornado/log.py
imports: import logging
  import logging.handlers
  import sys
  from tornado.escape import _unicode
  from tornado.util import unicode_type, basestring_type
  from typing import Dict, Any, cast, Optional
label_desc: Use image node_id 2 for calling the LogFormatter obj's underlying member method code with example usage: obj.format(record) and returns: formatted