r""" :arg bool color: Enables color support. :arg str fmt: Log message format. It will be applied to the attributes dict of log records. The text between ``%(color)s`` and ``%(end_color)s`` will be colored depending on the level if color support is on.
(
self,
fmt: str = DEFAULT_FORMAT,
datefmt: str = DEFAULT_DATE_FORMAT,
style: str = "%",
color: bool = True,
colors: Dict[int, int] = DEFAULT_COLORS,
)
| 114 | } |
| 115 | |
| 116 | def __init__( |
| 117 | self, |
| 118 | fmt: str = DEFAULT_FORMAT, |
| 119 | datefmt: str = DEFAULT_DATE_FORMAT, |
| 120 | style: str = "%", |
| 121 | color: bool = True, |
| 122 | colors: Dict[int, int] = DEFAULT_COLORS, |
| 123 | ) -> None: |
| 124 | r""" |
| 125 | :arg bool color: Enables color support. |
| 126 | :arg str fmt: Log message format. |
| 127 | It will be applied to the attributes dict of log records. The |
| 128 | text between ``%(color)s`` and ``%(end_color)s`` will be colored |
| 129 | depending on the level if color support is on. |
| 130 | :arg dict colors: color mappings from logging level to terminal color |
| 131 | code |
| 132 | :arg str datefmt: Datetime format. |
| 133 | Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``. |
| 134 | |
| 135 | .. versionchanged:: 3.2 |
| 136 | |
| 137 | Added ``fmt`` and ``datefmt`` arguments. |
| 138 | """ |
| 139 | logging.Formatter.__init__(self, datefmt=datefmt) |
| 140 | self._fmt = fmt |
| 141 | |
| 142 | self._colors = {} # type: Dict[int, str] |
| 143 | if color and _stderr_supports_color(): |
| 144 | if curses is not None: |
| 145 | fg_color = curses.tigetstr("setaf") or curses.tigetstr("setf") or b"" |
| 146 | |
| 147 | for levelno, code in colors.items(): |
| 148 | # Convert the terminal control characters from |
| 149 | # bytes to unicode strings for easier use with the |
| 150 | # logging module. |
| 151 | self._colors[levelno] = unicode_type( |
| 152 | curses.tparm(fg_color, code), "ascii" |
| 153 | ) |
| 154 | normal = curses.tigetstr("sgr0") |
| 155 | if normal is not None: |
| 156 | self._normal = unicode_type(normal, "ascii") |
| 157 | else: |
| 158 | self._normal = "" |
| 159 | else: |
| 160 | # If curses is not present (currently we'll only get here for |
| 161 | # colorama on windows), assume hard-coded ANSI color codes. |
| 162 | for levelno, code in colors.items(): |
| 163 | self._colors[levelno] = "\033[2;3%dm" % code |
| 164 | self._normal = "\033[0m" |
| 165 | else: |
| 166 | self._normal = "" |
| 167 | |
| 168 | def format(self, record: Any) -> str: |
| 169 | try: |
nothing calls this directly
no test coverage detected