rich/docs/source/logging.rst

17 lines
471 B
ReStructuredText
Raw Normal View History

2020-03-27 08:58:22 +00:00
Logging Handler
===============
2020-03-27 08:53:58 +00:00
Rich supplies a :ref:`logging handler<logging>` which will format and colorize text written by Python's logging module.
Here's an example of how to set up a rich logger::
import logging
from rich.logging import RichHandler
FORMAT = "%(message)s"
logging.basicConfig(
2020-05-19 12:38:13 +00:00
level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
2020-03-27 08:53:58 +00:00
)
2020-03-27 08:58:22 +00:00
2020-03-27 08:53:58 +00:00
log = logging.getLogger("rich")
log.info("Hello, World!")