[Python] How to set a formatter for file handler that will replace unwanted characters?

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I have python logger set, which has 2 handlers - 1 for stdout, 1 for file.

    Some of the logs i have, contains ANSI Escape characters for colorizing logs in stdout, e.g.

    SomeExampleText.... [32mPASS[0m....


    I would like to utilize solution in following thread:

    How can I remove the ANSI escape sequences from a string in python

    In order to adjust my logger, to strip out the "color" related characters, But only when logging into fileHandler -

    Keep the stdout colored, but my log file without any color related characters.

    How can I achieve that?

    Continue reading...

Compartilhe esta Página