From 298567f64c62f04f7900a6d74f4c52d8d8ee84c5 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 15 Feb 2023 12:39:37 +0000 Subject: [PATCH] [FIX] core: disable werkzeug log color when logging to file Werkzeug 1.0 colorised some outputs on POSIX IFF `click` was installed. Since 2.0 (pallets/werkzeug#2012) werkzeug unconditionally colorises the log on POSIX. This is annoying when using output redirection (let alone logging to a non-stream), as werkzeug will dump ANSI color codes to the non-term stdout and thus the logfile. Werkzeug provides no official knob to control this behaviour, but it does have a secret flag which is normally used to check if colorama is available on windows (so the ANSI codes are not output if colorama won't be interpreting and stripping them on the way out). Since `werkzeug.serving` is available in pretty much all versions, we can just (un)set this flag if not logging to a tty, and versions 2+ should pick it up and disable colorisation. closes odoo/odoo#112829 X-original-commit: 7c9f883dc508a7a8a45bf7bf7e900da0be9b34be Signed-off-by: Christophe Monniez (moc) Signed-off-by: Xavier Morel (xmo) --- odoo/netsvc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/odoo/netsvc.py b/odoo/netsvc.py index 8911ade410c..3db2319c971 100644 --- a/odoo/netsvc.py +++ b/odoo/netsvc.py @@ -12,6 +12,8 @@ import time import traceback import warnings +import werkzeug.serving + from . import release from . import sql_db from . import tools @@ -207,6 +209,7 @@ def init_logger(): else: formatter = DBFormatter(format) perf_filter = PerfFilter() + werkzeug.serving._log_add_style = False handler.setFormatter(formatter) logging.getLogger().addHandler(handler) logging.getLogger('werkzeug').addFilter(perf_filter)