forked from appium/appium-windows-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.ts
More file actions
39 lines (34 loc) · 1.07 KB
/
log.ts
File metadata and controls
39 lines (34 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import _ from 'lodash';
import type { WindowsDriver } from '../driver';
import { LogDefRecord, StringRecord } from '@appium/types';
const COLOR_CODE_PATTERN = /\u001b\[(\d+(;\d+)*)?m/g; // eslint-disable-line no-control-regex
const GET_SERVER_LOGS_FEATURE = 'get_server_logs';
const DEFAULT_LOG_LEVEL = 'ALL';
export const supportedLogTypes: LogDefRecord = {
server: {
description: 'Appium server logs',
getter: (self: WindowsDriver): LogEntry[] => {
self.assertFeatureEnabled(GET_SERVER_LOGS_FEATURE);
return self.log.unwrap().record.map(nativeLogEntryToSeleniumEntry);
},
},
};
function nativeLogEntryToSeleniumEntry(x: StringRecord): LogEntry {
const msg = _.isEmpty(x.prefix) ? x.message : `[${x.prefix}] ${x.message}`;
return toLogEntry(
_.replace(msg, COLOR_CODE_PATTERN, ''),
x.timestamp ?? Date.now()
);
}
function toLogEntry(
message: string,
timestamp: number,
level: string = DEFAULT_LOG_LEVEL
): LogEntry {
return { timestamp, level, message };
}
interface LogEntry {
timestamp: number;
level: string;
message: string;
}