python - Change logging colors in PyDev windows -
i'm using pydev , i'm trying change default colors of logging messages (for example - make info green...). i've tried use colorlog , colorama colors in console (both standard , interactive) remain same.
below code i've used:
import logging import colorlog colorlog import coloredformatter import colorama colorama import init init() formatter = coloredformatter("%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s", datefmt=none, reset=true, log_colors={ 'debug': 'cyan', 'info': 'green', 'warning': 'yellow', 'error': 'red', 'critical': 'red', } ) logger = logging.getlogger('example') handler = logging.streamhandler() handler.setformatter(formatter) logger.addhandler(handler) logger.setlevel(logging.debug) return logger def main(): """create , use logger.""" logger = setup_logger() logger.debug('a debug message') logger.info('an info message') logger.warning('a warning message') logger.error('an error message') logger.critical('a critical message') if __name__ == '__main__': main()
well, default eclipse console view doesn't handle ansi escape colors properly, can install plugin enable it:
https://marketplace.eclipse.org/content/ansi-escape-console
by using plugin should show colors when regular run...
i'm pasting code below shows how deal ansi escape sequences properly:
class ansicolors: fg_black = '\033[30m' fg_red = '\033[31m' fg_green = '\033[32m' fg_yellow = '\033[33m' fg_blue = '\033[34m' fg_magenta = '\033[35m' fg_cyan = '\033[36m' fg_white = '\033[37m' bg_black = '\033[40m' bg_red = '\033[41m' bg_green = '\033[42m' bg_yellow = '\033[43m' bg_blue = '\033[44m' bg_magenta = '\033[45m' bg_cyan = '\033[46m' bg_white = '\033[47m' end = '\033[0m' d in dir(ansicolors): if d.startswith("fg"): print(getattr(ansicolors, d) + d + ansicolors.end) if d.startswith("bg"): print(getattr(ansicolors, d) + d + ansicolors.end)
this should give output such as:
note should work in interactive console default too, unfortunately there's bug in pydev 4.3.0 prevents working (but it'll fixed pydev 4.4.0).
Comments
Post a Comment