Skip to content

Commit

Permalink
fix: Strip colors from server logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Sep 13, 2024
1 parent d2bb3a7 commit c5ce256
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {errors} from 'appium/driver';
export const ADB_SHELL_FEATURE = 'adb_shell';
export const BIDI_EVENT_NAME = 'bidiEvent';
export const GET_SERVER_LOGS_FEATURE = 'get_server_logs';
const COLOR_CODE_PATTERN = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex

/**
* Assert the presence of particular keys in the given object
Expand Down Expand Up @@ -64,9 +65,10 @@ export async function removeAllSessionWebSocketHandlers(server, sessionId) {
* @returns {LogEntry}
*/
export function nativeLogEntryToSeleniumEntry (x) {
const msg = _.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`;
return toLogRecord(
_.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`,
/** @type {any} */ (x).timestamp ?? Date.now()
/** @type {any} */ (x).timestamp ?? Date.now(),
_.replace(msg, COLOR_CODE_PATTERN, '')
);
}

Expand Down

0 comments on commit c5ce256

Please sign in to comment.