Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Strip colors from server logs #958

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading