[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) <moc@odoo.com> Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user