Recording messages using the stream handler is displayed in red in the console

I installed the registrar using the following code

def setup_logging(): import logging import logging.handlers import os #from time import gmtime, strftime #import logging.handlers logger = logging.getLogger('apt') logger.setLevel(logging.DEBUG) # create file handler fh = logging.handlers.RotatingFileHandler(os.path.join('..','logs','apt.log'), maxBytes=1000000, backupCount=5) fh.setLevel(logging.DEBUG) # create console handler ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) # create formatter and add it to the handlers formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) fh.setFormatter(formatter) # add the handlers to logger logger.addHandler(ch) logger.addHandler(fh) 

Prints log messages for both the file and the console (this is what I was after). The only problem is that the console message is red. This is distracting, since red makes everything look like an error (when it's just information). How can I change it so that console messages are in a different color?

Ideally, black for debugging and information, red for warning and above.

I use Eclipse and PyDev.

+4
source share
1 answer

The PyDev console highlights messages for stderr in red by default. Python logging.DEBUG will send messages to stderr. If you want to change this behavior, see This Post: Logging, StreamHandler, and Standard Streams

To change colors in PyDev, see here: http://pydev.org/manual_adv_interactive_console.html

+7
source

Source: https://habr.com/ru/post/1435318/


All Articles