I've setup a logger 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)
The prints the log messages to both a file and the console (which is what I was after). The only issue is that the console message are red. This is distracting since red makes everything look like an error (when it just info). How can I change it so that the console messages are a different color?
Ideally, black for debug and info, red for warning and above.
I'm using Eclipse and PyDev.