mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 10:08:40 +00:00
handle exceptions with rich's logging handler
This commit is contained in:
parent
4e24f2ef1a
commit
0fac8d5eab
3 changed files with 95 additions and 11 deletions
|
@ -20,4 +20,17 @@ Rich logs won't render :ref:`console_markup` in logging by default as most libra
|
|||
|
||||
log.error("[bold red blink]Server is shutting down![/]", extra={"markup": True})
|
||||
|
||||
|
||||
Handle exceptions
|
||||
-------------------
|
||||
|
||||
Rich's :class:`~rich.logging.RichHandler` class can be configured to handle exceptions. Here's an example::
|
||||
|
||||
handler = RichHandler(handle_tracebacks=True)
|
||||
|
||||
try:
|
||||
1 / 0
|
||||
except ZeroDivisionError:
|
||||
log.exception("Exception message")
|
||||
|
||||
There are a number of options you can use to configure logging output, see the :class:`~rich.logging.RichHandler` reference for details.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue