rich.logging

class rich.logging.RichHandler(level: int = 0, console: rich.console.Console = None, *, show_time: bool = True, show_level: bool = True, show_path: bool = True, enable_link_path: bool = True, highlighter: rich.highlighter.Highlighter = None, markup: bool = False, rich_tracebacks: bool = False, tracebacks_width: Optional[int] = 88, tracebacks_extra_lines: int = 3, tracebacks_theme: Optional[str] = None, tracebacks_word_wrap: bool = True)[source]

A logging handler that renders output with Rich. The time / level / message and file are displayed in columns. The level is color coded, and the message is syntax highlighted.

Note

Be careful when enabling console markup in log messages if you have configured logging for libraries not under your control. If a dependency writes messages containing square brackets, it may not produce the intended output.

Parameters
  • level (int, optional) – Log level. Defaults to logging.NOTSET.

  • console (Console, optional) – Optional console instance to write logs. Default will use a global console instance writing to stdout.

  • show_time (bool, optional) – Show a column for the time. Defaults to True.

  • show_level (bool, optional) – Show a column for the level. Defaults to True.

  • show_path (bool, optional) – Show the path to the original log call. Defaults to True.

  • enable_link_path (bool, optional) – Enable terminal link of path column to file. Defaults to True.

  • highlighter (Highlighter, optional) – Highlighter to style log messages, or None to use ReprHighlighter. Defaults to None.

  • markup (bool, optional) – Enable console markup in log messages. Defaults to False.

  • rich_tracebacks (bool, optional) – Enable rich tracebacks with syntax highlighting and formatting. Defaults to False.

  • tracebacks_width (Optional[int], optional) – Number of characters used to render tracebacks code. Defaults to 88.

  • tracebacks_extra_lines (int, optional) – Additional lines of code to render tracebacks, or None for full width. Defaults to None.

  • tracebacks_theme (str, optional) – Override pygments theme used in traceback.

  • tracebacks_word_wrap (bool, optional) – Enable word wrapping of long tracebacks lines. Defaults to False.

HIGHLIGHTER_CLASS

alias of rich.highlighter.ReprHighlighter

emit(record: logging.LogRecord) → None[source]

Invoked by logging.