5

I am using RichHander to format log output inside Python. While this works great locally, when I run inside GitLab, it seems to default to using a terminal that is 80 characters wide. This makes the output fairly difficult to read and scan quickly. I would like to change this default width for the RichHandler, but I don't see a way to do it.

Is there a way to set a minimum console width for the Python RichHandler log handler?

# Pseudocode:
    
import logging
from rich.logging import RichHandler

def setup_logging():
  logger = logging.getLogger('myLogger')
  richFormatter = logging.Formatter('%(message)s')
  richHandler = RichHandler()
  # Something like: richHandler.setMinimumWidth(255)
  richHandler.setFormatter(richFormatter)
  logger.addHandler(richHandler)
DiB
  • 554
  • 5
  • 19
  • I think that gitlab is piping the output of locally runned commands and thus, RichHandler defaults to 80 character wide, which I think is pretty standard for a default. As for the original question, I cannot help any further. – AmaanK Jun 12 '22 at 15:10
  • 1
    @xcodz-dot That was my assumption as well. Fixing the output might be easier from the RichHandler side than the GitLab Runner console output side. – DiB Jun 12 '22 at 15:20

1 Answers1

3

Add console=Console(width=255) to the handler constructor.

Will McGugan
  • 2,005
  • 13
  • 10