I'm using logging to log some information.
I used both FileHandler and StreamHandler in my logger, to output the message in the console and saved to a specific file.
In the console, to highlight some important message, I used \033. But this word also add into my log file and shown a weird symbol. Following is my currently usage example
logger = logging.getLogger('SayHello')
file_hdlr = logging.FileHandler('test.log')
file_hdlr.setFormatter(logging.Formatter('%(message)s'))
console_hdlr = logging.StreamHandler()
console_hdlr.setFormatter(logging.Formatter('%(message)s'))
logger.addHandler(file_hdlr)
logger.addHandler(console_hdlr)
logger.setLevel(logging.INFO)
logger.info('\033[1;31mHello World\033[0m')
Output in console: Hello World (in red)
Output in log file: [1;31mHello World[0m
How can I ignore the \033 and other color code in my file handler? Should I override the FileHandler class? Thanks a lot!