ashb commented on issue #5681: [AIRFLOW-5065] Add colors to console log URL: https://github.com/apache/airflow/pull/5681#issuecomment-516370691 `coloredlogs` doesn't look like it gives the flexability we want (the different colours for each of the parts is _really_ nice) but https://github.com/borntyping/python-colorlog (`pip install colorlog`) is close: ```python from colorlog import ColoredFormatter import logging logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) log_format = '[%(blue)s%(asctime)s%(reset)s] {%(blue)s%(filename)s%(reset)s:%(lineno)d} %(log_color)s%(levelname)s%(reset)s - %(message_log_color)s%(message)s' formatter = ColoredFormatter( log_format, log_colors={ 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red,bold', }, secondary_log_colors={ 'message': { 'INFO': 'bold', } }, ) logging.root.handlers[0].setFormatter(formatter) log.info("Usiung connection to: %s", {'id': 'proxy_postgres_tcp'}) log.warning("Hi") log.error("Hi") try: raise RuntimeError("x") except Exception: log.critical("err") ``` Looks like:  And it automatically detects when in a TTY. _But_ it may not be written in a way that lets us get the colours we want.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
