In a Flask application, I use a RotatingFileLogger
to log werkzeug access logs to a file like shown in this question:
file_handler_access_log = RotatingFileHandler("access.log",
backupCount=5,
encoding='utf-8')
formatter = logging.Formatter('%(asctime)s %(module)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
file_handler_access_log.setFormatter(formatter)
werkzeug_logger.addHandler(file_handler_access_log)
werkzeug_logger.setLevel(logging.DEBUG)
In the access.log
file, the request looks like this:
2020-10-07 09:43:51 _internal INFO: 127.0.0.1 - - [07/Oct/2020 09:43:51] "[37mGET /api/foo HTTP/1.1[0m" 200 -
I want to get rid of the color codes like [37m
in the log file.
The werkzeug documentation states:
The development server can optionally highlight the request logs in different colors based on the status code. Install Click to enable this feature.
Click is a Flask dependency, so I cannot uninstall it. How can I disable the colored logging?
formatter
definition? – Rellia%(message)s
part. – Euthanasia