

This has the colour when it outputs to stdout, but not in the log file. Logging.error("This is just an information for you") Logging.warning("This is just an information for you") Streamhandler = logging.StreamHandler(sys.stdout) Loghandler = logging.FileHandler("log.txt", mode="w", encoding="utf8")

Re.sub(self.ANSI_RE, "", record.levelname),Ĭolorformatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") """Return logger message with terminal escapes removed.""" Log formatter that strips terminal colour 'ERROR': lambda: logging.addLevelName(logging.WARNING, escaped % ('91', level))Ĭlass NoColorFormatter(logging.Formatter): 'WARNING': lambda: logging.addLevelName(logging.ERROR, escaped % ('93', level)), 'INFO': lambda: logging.addLevelName(logging.INFO, escaped % ('94', level)), Sets colour of text for the level name in Here's something that could be used directly to produce the logging you want: import logging To change colours, all is needed is to replace the corresponding number in set_colours() to the desired value. Updated to have individual colours assigned to each level.
