handle exceptions with rich's logging handler

This commit is contained in:
landi 2020-09-23 00:49:49 +02:00
parent 4e24f2ef1a
commit 0fac8d5eab
3 changed files with 95 additions and 11 deletions

View file

@ -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.