Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions colorlog/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
import sys
import typing
import traceback
import io

import colorlog.escape_codes

Expand Down Expand Up @@ -175,6 +177,29 @@ def _append_reset(self, message: str, escapes: EscapeCodes) -> str:

return message

if sys.version_info >= (3, 13):

def formatException(self, ei):
"""Format and return the specified exception information as a string."""
# This is a copy of logging.Formatter.formatException that passes in
# an appropriate value for colorize to print_exception.

sio = io.StringIO()
tb = ei[2]
traceback.print_exception(
ei[0],
ei[1],
tb,
limit=None,
file=sio,
colorize=not self._blank_escape_codes(),
)
s = sio.getvalue()
sio.close()
if s[-1:] == "\n":
s = s[:-1]
return s


class LevelFormatter:
"""An extension of ColoredFormatter that uses per-level format strings."""
Expand Down
Loading