Skip to content
Discussion options

You must be logged in to vote

Answering my own question here, it's pretty simple to use setFormatter on the Instance of the Loghandler, forcing it to use a different handler.

This way, Rich get's "nice" outputs, while other handlers are not impacted.

Full sample:

import logging
from logging import Formatter
from rich.progress import track
from rich.console import Console
from rich.logging import RichHandler
import time

from logging.handlers import  RotatingFileHandler
LOGFORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
LOGFORMAT_RICH = '%(message)s'

error_console = Console(stderr=True)

rh = RichHandler(console=error_console)

rh.setFormatter(Formatter(LOGFORMAT_RICH))

logging.basicConfig(
    level=l…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by xmatthias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant