Replies: 3 comments 12 replies
-
If you are using RichHandler, then you can't change that behaviour. It's designed to format it for the terminal and wrapping is necessary for neat columns. If you want to also log to a file, you can configure a FileHandler (or any other logging handler(s)) in conjunction with the Rich handler. |
Beta Was this translation helpful? Give feedback.
-
I was already able to created a custom FluidLogRender class that does not make use of Table(Columns) and had partial success with it. Still, I am still facing some issues related to some wrapping coming from other places. For example I found that Text() has an implicit no_wrap=None (same as False) which is called from various places. I tried to hack Rich to temporary make no_wrap=True but it was not enough. Maybe you could give me a hint on how to render the text without any wrapping to occur. |
Beta Was this translation helpful? Give feedback.
-
Maybe simple workaround is this use custome handler like this. You can modify format to format other things to import logging
from rich.console import Console
rprint = Console(soft_wrap=True).print
class MyRichLogHandler(logging.Handler):
LEVEL_MAPPING = {
logging.DEBUG: "[blue]DEBUG[/blue]",
logging.INFO: "[green]INFO[/green]",
logging.WARNING: "[yellow]WARNING[/yellow]",
logging.ERROR: "[red]ERROR[/red]",
logging.CRITICAL: "[bold red]CRITICAL[/bold red]",
}
def emit(self, record):
msg = self.format(record)
rprint(msg)
def format(self, record):
levelname = self.LEVEL_MAPPING.get(record.levelno, str(record.levelno))
file_name_line = (
f"[link file://{record.filename}#{record.lineno}]"
f"{record.filename}:{record.lineno}"
f"[/link file://{record.filename}#{record.lineno}]")
record.levelname = levelname
record.filename = file_name_line
return super().format(record) You can modify in this example if you set |
Beta Was this translation helpful? Give feedback.
-
While replacing the standard python logger with a rich one I discovered that longer lines get wrapped and that normal lines do get extra padding at the end, both being undesired actions, especially as same logging result can be sent to files or other apps for further processing.
I tried adding
width=0
to Console instance used for logger but that basically broke it and produced no output.None
seems to be reserved to auto-detection. I also tried putting a very big value but that produced very long spam lines, even when called withconsole=False
How can I make the rich logging not add extra padding and avoid any wrapping?
Beta Was this translation helpful? Give feedback.
All reactions