2

In my Python code I log to stderr and to a file with this configuration:

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s : %(name)s - %(levelname)s - %(message)s",
    handlers=[
        logging.FileHandler(
            my_network_folder / "publish.log"
        ),  
        logging.StreamHandler(),  # stderr
    ],
)

My problem is that sometimes it is run using Rundeck and displays a garbled console output. I have no way to control the rundeck encoding, so I'd like to change the encoding of StreamHandler for the encoding of Rundeck.

FileHandler has an encodingparameter, but I didn't find this option for the Stream handler. I'd like to do a StreamHander(encoding='latin-1').

How can I set the console encoding?

neves
  • 33,186
  • 27
  • 159
  • 192

0 Answers0