From 661f9d3f0fcb0d483de137fc542de141f077b1dc Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 13 Sep 2024 15:35:45 +0200 Subject: [PATCH] fix: Strip colors from server logs (#2466) --- lib/commands/log.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/commands/log.js b/lib/commands/log.js index 1ebe96557..439e0adf6 100644 --- a/lib/commands/log.js +++ b/lib/commands/log.js @@ -17,7 +17,7 @@ import { NATIVE_WIN, BIDI_EVENT_NAME } from '../utils'; */ const WEBSOCKET_ENDPOINT = (sessionId) => `${DEFAULT_WS_PATHNAME_PREFIX}/session/${sessionId}/appium/device/syslog`; - +const COLOR_CODE_PATTERN = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex const GET_SERVER_LOGS_FEATURE = 'get_server_logs'; /** @@ -26,8 +26,9 @@ const GET_SERVER_LOGS_FEATURE = 'get_server_logs'; * @returns {import('./types').LogEntry} */ function nativeLogEntryToSeleniumEntry (x) { + const msg = _.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`; return toLogEntry( - _.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`, + _.replace(msg, COLOR_CODE_PATTERN, ''), /** @type {any} */ (x).timestamp ?? Date.now() ); }