appium-adb 14.0.1 → 14.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/lib/logcat.d.ts +24 -38
- package/build/lib/logcat.d.ts.map +1 -1
- package/build/lib/logcat.js +80 -101
- package/build/lib/logcat.js.map +1 -1
- package/lib/{logcat.js → logcat.ts} +114 -117
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [14.0.3](https://github.com/appium/appium-adb/compare/v14.0.2...v14.0.3) (2025-11-15)
|
|
2
|
+
|
|
3
|
+
### Miscellaneous Chores
|
|
4
|
+
|
|
5
|
+
* publish via trusted publisher ([#829](https://github.com/appium/appium-adb/issues/829)) ([967943a](https://github.com/appium/appium-adb/commit/967943adf24031111d5a7cefc088a457050d2861))
|
|
6
|
+
|
|
7
|
+
## [14.0.2](https://github.com/appium/appium-adb/compare/v14.0.1...v14.0.2) (2025-11-10)
|
|
8
|
+
|
|
9
|
+
### Miscellaneous Chores
|
|
10
|
+
|
|
11
|
+
* Migrate logcat.js to logcat.ts ([#828](https://github.com/appium/appium-adb/issues/828)) ([7148a42](https://github.com/appium/appium-adb/commit/7148a428706588e8278ea78a97cbc2773ea14bcf))
|
|
12
|
+
|
|
1
13
|
## [14.0.1](https://github.com/appium/appium-adb/compare/v14.0.0...v14.0.1) (2025-11-07)
|
|
2
14
|
|
|
3
15
|
### Miscellaneous Chores
|
package/build/lib/logcat.d.ts
CHANGED
|
@@ -1,43 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @returns {Promise<void>}
|
|
24
|
-
*/
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { ADBExecutable } from './types';
|
|
3
|
+
import type { LogEntry, LogcatOpts as StartCaptureOptions } from './tools/types';
|
|
4
|
+
export interface LogcatOptions {
|
|
5
|
+
adb: ADBExecutable;
|
|
6
|
+
clearDeviceLogsOnStart?: boolean;
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
debugTrace?: boolean;
|
|
9
|
+
maxBufferSize?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class Logcat extends EventEmitter {
|
|
12
|
+
private readonly adb;
|
|
13
|
+
private readonly clearLogs;
|
|
14
|
+
private readonly debug?;
|
|
15
|
+
private readonly debugTrace?;
|
|
16
|
+
private readonly maxBufferSize;
|
|
17
|
+
private readonly logs;
|
|
18
|
+
private logIndexSinceLastRequest;
|
|
19
|
+
private proc;
|
|
20
|
+
constructor(opts: LogcatOptions);
|
|
21
|
+
startCapture(opts?: StartCaptureOptions): Promise<void>;
|
|
25
22
|
stopCapture(): Promise<void>;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
getLogs(): import("./tools/types").LogEntry[];
|
|
30
|
-
/**
|
|
31
|
-
* @returns {import('./tools/types').LogEntry[]}
|
|
32
|
-
*/
|
|
33
|
-
getAllLogs(): import("./tools/types").LogEntry[];
|
|
34
|
-
/**
|
|
35
|
-
* @returns {Promise<void>}
|
|
36
|
-
*/
|
|
23
|
+
getLogs(): LogEntry[];
|
|
24
|
+
getAllLogs(): LogEntry[];
|
|
37
25
|
clear(): Promise<void>;
|
|
26
|
+
private outputHandler;
|
|
38
27
|
}
|
|
39
28
|
export default Logcat;
|
|
40
|
-
import { EventEmitter } from 'node:events';
|
|
41
|
-
import { LRUCache } from 'lru-cache';
|
|
42
|
-
import { SubProcess } from 'teen_process';
|
|
43
29
|
//# sourceMappingURL=logcat.d.ts.map
|
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
package/build/lib/logcat.js
CHANGED
|
@@ -20,78 +20,27 @@ const DEFAULT_TAG = '*';
|
|
|
20
20
|
const DEFAULT_FORMAT = 'threadtime';
|
|
21
21
|
const TRACE_PATTERN = /W\/Trace/;
|
|
22
22
|
const EXECVP_ERR_PATTERN = /execvp\(\)/;
|
|
23
|
-
function requireFormat(format) {
|
|
24
|
-
if (!SUPPORTED_FORMATS.includes(format)) {
|
|
25
|
-
log.info(`The format value '${format}' is unknown. Supported values are: ${SUPPORTED_FORMATS}`);
|
|
26
|
-
log.info(`Defaulting to '${DEFAULT_FORMAT}'`);
|
|
27
|
-
return DEFAULT_FORMAT;
|
|
28
|
-
}
|
|
29
|
-
return format;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param {string} message
|
|
34
|
-
* @param {number} timestamp
|
|
35
|
-
* @returns {import('./tools/types').LogEntry}
|
|
36
|
-
*/
|
|
37
|
-
function toLogEntry(message, timestamp) {
|
|
38
|
-
return {
|
|
39
|
-
timestamp,
|
|
40
|
-
level: 'ALL',
|
|
41
|
-
message,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {string} spec
|
|
47
|
-
* @returns {string}
|
|
48
|
-
*/
|
|
49
|
-
function requireSpec(spec) {
|
|
50
|
-
const [tag, priority] = spec.split(':');
|
|
51
|
-
let resultTag = tag;
|
|
52
|
-
if (!resultTag) {
|
|
53
|
-
log.info(`The tag value in spec '${spec}' cannot be empty`);
|
|
54
|
-
log.info(`Defaulting to '${DEFAULT_TAG}'`);
|
|
55
|
-
resultTag = DEFAULT_TAG;
|
|
56
|
-
}
|
|
57
|
-
if (!priority) {
|
|
58
|
-
log.info(`The priority value in spec '${spec}' is empty. Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
59
|
-
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
60
|
-
}
|
|
61
|
-
if (!SUPPORTED_PRIORITIES.some((p) => lodash_1.default.toLower(priority) === lodash_1.default.toLower(p))) {
|
|
62
|
-
log.info(`The priority value in spec '${spec}' is unknown. Supported values are: ${SUPPORTED_PRIORITIES}`);
|
|
63
|
-
log.info(`Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
64
|
-
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
65
|
-
}
|
|
66
|
-
return spec;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
*
|
|
70
|
-
* @param {string|string[]} filterSpecs
|
|
71
|
-
* @returns {string[]}
|
|
72
|
-
*/
|
|
73
|
-
function formatFilterSpecs(filterSpecs) {
|
|
74
|
-
if (!lodash_1.default.isArray(filterSpecs)) {
|
|
75
|
-
filterSpecs = [filterSpecs];
|
|
76
|
-
}
|
|
77
|
-
return filterSpecs
|
|
78
|
-
.filter((spec) => spec && lodash_1.default.isString(spec) && !spec.startsWith('-'))
|
|
79
|
-
.map((spec) => spec.includes(':') ? requireSpec(spec) : spec);
|
|
80
|
-
}
|
|
81
23
|
class Logcat extends node_events_1.EventEmitter {
|
|
82
|
-
|
|
24
|
+
adb;
|
|
25
|
+
clearLogs;
|
|
26
|
+
debug;
|
|
27
|
+
debugTrace;
|
|
28
|
+
maxBufferSize;
|
|
29
|
+
logs;
|
|
30
|
+
logIndexSinceLastRequest;
|
|
31
|
+
proc;
|
|
32
|
+
constructor(opts) {
|
|
83
33
|
super();
|
|
84
34
|
this.adb = opts.adb;
|
|
85
35
|
this.clearLogs = opts.clearDeviceLogsOnStart || false;
|
|
86
36
|
this.debug = opts.debug;
|
|
87
37
|
this.debugTrace = opts.debugTrace;
|
|
88
38
|
this.maxBufferSize = opts.maxBufferSize || MAX_BUFFER_SIZE;
|
|
89
|
-
/** @type {LRUCache<number, [string, number]>} */
|
|
90
39
|
this.logs = new lru_cache_1.LRUCache({
|
|
91
40
|
max: this.maxBufferSize,
|
|
92
41
|
});
|
|
93
|
-
/** @type {number?} */
|
|
94
42
|
this.logIndexSinceLastRequest = null;
|
|
43
|
+
this.proc = null;
|
|
95
44
|
}
|
|
96
45
|
async startCapture(opts = {}) {
|
|
97
46
|
let started = false;
|
|
@@ -141,31 +90,6 @@ class Logcat extends node_events_1.EventEmitter {
|
|
|
141
90
|
setTimeout(resolve, LOGCAT_PROC_STARTUP_TIMEOUT);
|
|
142
91
|
});
|
|
143
92
|
}
|
|
144
|
-
/**
|
|
145
|
-
*
|
|
146
|
-
* @param {string} logLine
|
|
147
|
-
* @param {string} [prefix='']
|
|
148
|
-
* @returns {void}
|
|
149
|
-
*/
|
|
150
|
-
outputHandler(logLine, prefix = '') {
|
|
151
|
-
const timestamp = Date.now();
|
|
152
|
-
let recentIndex = -1;
|
|
153
|
-
for (const key of this.logs.keys()) {
|
|
154
|
-
recentIndex = key;
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
this.logs.set(++recentIndex, [logLine, timestamp]);
|
|
158
|
-
if (this.listenerCount('output')) {
|
|
159
|
-
this.emit('output', toLogEntry(logLine, timestamp));
|
|
160
|
-
}
|
|
161
|
-
if (this.debug && (this.debugTrace || !TRACE_PATTERN.test(logLine))) {
|
|
162
|
-
log.debug(prefix + logLine);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
*
|
|
167
|
-
* @returns {Promise<void>}
|
|
168
|
-
*/
|
|
169
93
|
async stopCapture() {
|
|
170
94
|
log.debug('Stopping logcat capture');
|
|
171
95
|
if (!this.proc?.isRunning) {
|
|
@@ -177,15 +101,15 @@ class Logcat extends node_events_1.EventEmitter {
|
|
|
177
101
|
await this.proc.stop();
|
|
178
102
|
this.proc = null;
|
|
179
103
|
}
|
|
180
|
-
/**
|
|
181
|
-
* @returns {import('./tools/types').LogEntry[]}
|
|
182
|
-
*/
|
|
183
104
|
getLogs() {
|
|
184
|
-
/** @type {import('./tools/types').LogEntry[]} */
|
|
185
105
|
const result = [];
|
|
186
|
-
/** @type {number?} */
|
|
187
106
|
let recentLogIndex = null;
|
|
188
|
-
for (const
|
|
107
|
+
for (const entry of this.logs.rentries()) {
|
|
108
|
+
const [index, value] = entry;
|
|
109
|
+
if (typeof index !== 'number' || !Array.isArray(value)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const [message, timestamp] = value;
|
|
189
113
|
if (this.logIndexSinceLastRequest && index > this.logIndexSinceLastRequest
|
|
190
114
|
|| !this.logIndexSinceLastRequest) {
|
|
191
115
|
recentLogIndex = index;
|
|
@@ -197,20 +121,17 @@ class Logcat extends node_events_1.EventEmitter {
|
|
|
197
121
|
}
|
|
198
122
|
return result;
|
|
199
123
|
}
|
|
200
|
-
/**
|
|
201
|
-
* @returns {import('./tools/types').LogEntry[]}
|
|
202
|
-
*/
|
|
203
124
|
getAllLogs() {
|
|
204
|
-
/** @type {import('./tools/types').LogEntry[]} */
|
|
205
125
|
const result = [];
|
|
206
|
-
for (const
|
|
126
|
+
for (const value of this.logs.rvalues()) {
|
|
127
|
+
if (!Array.isArray(value)) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const [message, timestamp] = value;
|
|
207
131
|
result.push(toLogEntry(message, timestamp));
|
|
208
132
|
}
|
|
209
133
|
return result;
|
|
210
134
|
}
|
|
211
|
-
/**
|
|
212
|
-
* @returns {Promise<void>}
|
|
213
|
-
*/
|
|
214
135
|
async clear() {
|
|
215
136
|
log.debug('Clearing logcat logs from device');
|
|
216
137
|
try {
|
|
@@ -218,10 +139,68 @@ class Logcat extends node_events_1.EventEmitter {
|
|
|
218
139
|
await (0, teen_process_1.exec)(this.adb.path, args);
|
|
219
140
|
}
|
|
220
141
|
catch (err) {
|
|
221
|
-
|
|
142
|
+
const execErr = err;
|
|
143
|
+
log.warn(`Failed to clear logcat logs: ${execErr.stderr || execErr.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
outputHandler(logLine, prefix = '') {
|
|
147
|
+
const timestamp = Date.now();
|
|
148
|
+
let recentIndex = -1;
|
|
149
|
+
for (const key of this.logs.keys()) {
|
|
150
|
+
recentIndex = key;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
this.logs.set(++recentIndex, [logLine, timestamp]);
|
|
154
|
+
if (this.listenerCount('output')) {
|
|
155
|
+
this.emit('output', toLogEntry(logLine, timestamp));
|
|
156
|
+
}
|
|
157
|
+
if (this.debug && (this.debugTrace || !TRACE_PATTERN.test(logLine))) {
|
|
158
|
+
log.debug(prefix + logLine);
|
|
222
159
|
}
|
|
223
160
|
}
|
|
224
161
|
}
|
|
225
162
|
exports.Logcat = Logcat;
|
|
226
163
|
exports.default = Logcat;
|
|
164
|
+
function requireFormat(format) {
|
|
165
|
+
if (!SUPPORTED_FORMATS.includes(format)) {
|
|
166
|
+
log.info(`The format value '${format}' is unknown. Supported values are: ${SUPPORTED_FORMATS}`);
|
|
167
|
+
log.info(`Defaulting to '${DEFAULT_FORMAT}'`);
|
|
168
|
+
return DEFAULT_FORMAT;
|
|
169
|
+
}
|
|
170
|
+
return format;
|
|
171
|
+
}
|
|
172
|
+
function toLogEntry(message, timestamp) {
|
|
173
|
+
return {
|
|
174
|
+
timestamp,
|
|
175
|
+
level: 'ALL',
|
|
176
|
+
message,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function requireSpec(spec) {
|
|
180
|
+
const [tag, priority] = spec.split(':');
|
|
181
|
+
let resultTag = tag;
|
|
182
|
+
if (!resultTag) {
|
|
183
|
+
log.info(`The tag value in spec '${spec}' cannot be empty`);
|
|
184
|
+
log.info(`Defaulting to '${DEFAULT_TAG}'`);
|
|
185
|
+
resultTag = DEFAULT_TAG;
|
|
186
|
+
}
|
|
187
|
+
if (!priority) {
|
|
188
|
+
log.info(`The priority value in spec '${spec}' is empty. Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
189
|
+
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
190
|
+
}
|
|
191
|
+
if (!SUPPORTED_PRIORITIES.some((p) => lodash_1.default.toLower(priority) === lodash_1.default.toLower(p))) {
|
|
192
|
+
log.info(`The priority value in spec '${spec}' is unknown. Supported values are: ${SUPPORTED_PRIORITIES}`);
|
|
193
|
+
log.info(`Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
194
|
+
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
195
|
+
}
|
|
196
|
+
return spec;
|
|
197
|
+
}
|
|
198
|
+
function formatFilterSpecs(filterSpecs) {
|
|
199
|
+
if (!lodash_1.default.isArray(filterSpecs)) {
|
|
200
|
+
filterSpecs = [filterSpecs];
|
|
201
|
+
}
|
|
202
|
+
return filterSpecs
|
|
203
|
+
.filter((spec) => spec && lodash_1.default.isString(spec) && !spec.startsWith('-'))
|
|
204
|
+
.map((spec) => spec.includes(':') ? requireSpec(spec) : spec);
|
|
205
|
+
}
|
|
227
206
|
//# sourceMappingURL=logcat.js.map
|
package/build/lib/logcat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logcat.js","sourceRoot":"","sources":["../../lib/logcat.
|
|
1
|
+
{"version":3,"file":"logcat.js","sourceRoot":"","sources":["../../lib/logcat.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA+C;AAC/C,wDAAyB;AACzB,oDAAuB;AACvB,6CAA2C;AAC3C,+CAAgD;AAChD,yCAAqC;AAQrC,MAAM,GAAG,GAAG,gBAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AACvC,MAAM,eAAe,GAAG,KAAK,CAAC;AAC9B,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAC1C,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAU,CAAC;AAC9G,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AA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AC,WAA8B;IACvD,IAAI,CAAC,gBAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5B,WAAW,GAAG,CAAC,WAAW,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,WAAW;SACf,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACnE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -4,105 +4,64 @@ import _ from 'lodash';
|
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
5
|
import { SubProcess, exec } from 'teen_process';
|
|
6
6
|
import { LRUCache } from 'lru-cache';
|
|
7
|
+
import type { ExecError } from 'teen_process';
|
|
8
|
+
import type { ADBExecutable } from './types';
|
|
9
|
+
import type {
|
|
10
|
+
LogEntry,
|
|
11
|
+
LogcatOpts as StartCaptureOptions,
|
|
12
|
+
} from './tools/types';
|
|
7
13
|
|
|
8
14
|
const log = logger.getLogger('Logcat');
|
|
9
15
|
const MAX_BUFFER_SIZE = 10000;
|
|
10
16
|
const LOGCAT_PROC_STARTUP_TIMEOUT = 10000;
|
|
11
|
-
const SUPPORTED_FORMATS = ['brief', 'process', 'tag', 'thread', 'raw', 'time', 'threadtime', 'long'];
|
|
12
|
-
const SUPPORTED_PRIORITIES = ['v', 'd', 'i', 'w', 'e', 'f', 's'];
|
|
17
|
+
const SUPPORTED_FORMATS = ['brief', 'process', 'tag', 'thread', 'raw', 'time', 'threadtime', 'long'] as const;
|
|
18
|
+
const SUPPORTED_PRIORITIES = ['v', 'd', 'i', 'w', 'e', 'f', 's'] as const;
|
|
13
19
|
const DEFAULT_PRIORITY = 'v';
|
|
14
20
|
const DEFAULT_TAG = '*';
|
|
15
21
|
const DEFAULT_FORMAT = 'threadtime';
|
|
16
22
|
const TRACE_PATTERN = /W\/Trace/;
|
|
17
23
|
const EXECVP_ERR_PATTERN = /execvp\(\)/;
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return format;
|
|
25
|
+
export interface LogcatOptions {
|
|
26
|
+
adb: ADBExecutable;
|
|
27
|
+
clearDeviceLogsOnStart?: boolean;
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
debugTrace?: boolean;
|
|
30
|
+
maxBufferSize?: number;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @param {string} message
|
|
31
|
-
* @param {number} timestamp
|
|
32
|
-
* @returns {import('./tools/types').LogEntry}
|
|
33
|
-
*/
|
|
34
|
-
function toLogEntry(message, timestamp) {
|
|
35
|
-
return {
|
|
36
|
-
timestamp,
|
|
37
|
-
level: 'ALL',
|
|
38
|
-
message,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param {string} spec
|
|
45
|
-
* @returns {string}
|
|
46
|
-
*/
|
|
47
|
-
function requireSpec (spec) {
|
|
48
|
-
const [tag, priority] = spec.split(':');
|
|
49
|
-
let resultTag = tag;
|
|
50
|
-
if (!resultTag) {
|
|
51
|
-
log.info(`The tag value in spec '${spec}' cannot be empty`);
|
|
52
|
-
log.info(`Defaulting to '${DEFAULT_TAG}'`);
|
|
53
|
-
resultTag = DEFAULT_TAG;
|
|
54
|
-
}
|
|
55
|
-
if (!priority) {
|
|
56
|
-
log.info(`The priority value in spec '${spec}' is empty. Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
57
|
-
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
58
|
-
}
|
|
59
|
-
if (!SUPPORTED_PRIORITIES.some((p) => _.toLower(priority) === _.toLower(p))) {
|
|
60
|
-
log.info(`The priority value in spec '${spec}' is unknown. Supported values are: ${SUPPORTED_PRIORITIES}`);
|
|
61
|
-
log.info(`Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
62
|
-
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
63
|
-
}
|
|
64
|
-
return spec;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {string|string[]} filterSpecs
|
|
70
|
-
* @returns {string[]}
|
|
71
|
-
*/
|
|
72
|
-
function formatFilterSpecs (filterSpecs) {
|
|
73
|
-
if (!_.isArray(filterSpecs)) {
|
|
74
|
-
filterSpecs = [filterSpecs];
|
|
75
|
-
}
|
|
76
|
-
return filterSpecs
|
|
77
|
-
.filter((spec) => spec && _.isString(spec) && !spec.startsWith('-'))
|
|
78
|
-
.map((spec) => spec.includes(':') ? requireSpec(spec) : spec);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
33
|
export class Logcat extends EventEmitter {
|
|
83
|
-
|
|
34
|
+
private readonly adb: ADBExecutable;
|
|
35
|
+
private readonly clearLogs: boolean;
|
|
36
|
+
private readonly debug?: boolean;
|
|
37
|
+
private readonly debugTrace?: boolean;
|
|
38
|
+
private readonly maxBufferSize: number;
|
|
39
|
+
private readonly logs: LRUCache<number, [string, number]>;
|
|
40
|
+
private logIndexSinceLastRequest: number | null;
|
|
41
|
+
private proc: SubProcess | null;
|
|
42
|
+
|
|
43
|
+
constructor(opts: LogcatOptions) {
|
|
84
44
|
super();
|
|
85
45
|
this.adb = opts.adb;
|
|
86
46
|
this.clearLogs = opts.clearDeviceLogsOnStart || false;
|
|
87
47
|
this.debug = opts.debug;
|
|
88
48
|
this.debugTrace = opts.debugTrace;
|
|
89
49
|
this.maxBufferSize = opts.maxBufferSize || MAX_BUFFER_SIZE;
|
|
90
|
-
/** @type {LRUCache<number, [string, number]>} */
|
|
91
50
|
this.logs = new LRUCache({
|
|
92
51
|
max: this.maxBufferSize,
|
|
93
52
|
});
|
|
94
|
-
/** @type {number?} */
|
|
95
53
|
this.logIndexSinceLastRequest = null;
|
|
54
|
+
this.proc = null;
|
|
96
55
|
}
|
|
97
56
|
|
|
98
|
-
async startCapture
|
|
57
|
+
async startCapture(opts: StartCaptureOptions = {}): Promise<void> {
|
|
99
58
|
let started = false;
|
|
100
59
|
return await new B(async (_resolve, _reject) => {
|
|
101
|
-
const resolve = function (...args) {
|
|
60
|
+
const resolve = function (...args: any[]) {
|
|
102
61
|
started = true;
|
|
103
62
|
_resolve(...args);
|
|
104
63
|
};
|
|
105
|
-
const reject = function (...args) {
|
|
64
|
+
const reject = function (...args: any[]) {
|
|
106
65
|
started = true;
|
|
107
66
|
_reject(...args);
|
|
108
67
|
};
|
|
@@ -149,33 +108,7 @@ export class Logcat extends EventEmitter {
|
|
|
149
108
|
});
|
|
150
109
|
}
|
|
151
110
|
|
|
152
|
-
|
|
153
|
-
*
|
|
154
|
-
* @param {string} logLine
|
|
155
|
-
* @param {string} [prefix='']
|
|
156
|
-
* @returns {void}
|
|
157
|
-
*/
|
|
158
|
-
outputHandler (logLine, prefix = '') {
|
|
159
|
-
const timestamp = Date.now();
|
|
160
|
-
let recentIndex = -1;
|
|
161
|
-
for (const key of this.logs.keys()) {
|
|
162
|
-
recentIndex = key;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
this.logs.set(++recentIndex, [logLine, timestamp]);
|
|
166
|
-
if (this.listenerCount('output')) {
|
|
167
|
-
this.emit('output', toLogEntry(logLine, timestamp));
|
|
168
|
-
}
|
|
169
|
-
if (this.debug && (this.debugTrace || !TRACE_PATTERN.test(logLine))) {
|
|
170
|
-
log.debug(prefix + logLine);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
*
|
|
176
|
-
* @returns {Promise<void>}
|
|
177
|
-
*/
|
|
178
|
-
async stopCapture () {
|
|
111
|
+
async stopCapture(): Promise<void> {
|
|
179
112
|
log.debug('Stopping logcat capture');
|
|
180
113
|
if (!this.proc?.isRunning) {
|
|
181
114
|
log.debug('Logcat already stopped');
|
|
@@ -187,15 +120,15 @@ export class Logcat extends EventEmitter {
|
|
|
187
120
|
this.proc = null;
|
|
188
121
|
}
|
|
189
122
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
123
|
+
getLogs(): LogEntry[] {
|
|
124
|
+
const result: LogEntry[] = [];
|
|
125
|
+
let recentLogIndex: number | null = null;
|
|
126
|
+
for (const entry of this.logs.rentries()) {
|
|
127
|
+
const [index, value] = entry;
|
|
128
|
+
if (typeof index !== 'number' || !Array.isArray(value)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const [message, timestamp] = value;
|
|
199
132
|
if (this.logIndexSinceLastRequest && index > this.logIndexSinceLastRequest
|
|
200
133
|
|| !this.logIndexSinceLastRequest) {
|
|
201
134
|
recentLogIndex = index;
|
|
@@ -208,30 +141,94 @@ export class Logcat extends EventEmitter {
|
|
|
208
141
|
return result;
|
|
209
142
|
}
|
|
210
143
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
144
|
+
getAllLogs(): LogEntry[] {
|
|
145
|
+
const result: LogEntry[] = [];
|
|
146
|
+
for (const value of this.logs.rvalues()) {
|
|
147
|
+
if (!Array.isArray(value)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const [message, timestamp] = value;
|
|
218
151
|
result.push(toLogEntry(message, timestamp));
|
|
219
152
|
}
|
|
220
153
|
return result;
|
|
221
154
|
}
|
|
222
155
|
|
|
223
|
-
|
|
224
|
-
* @returns {Promise<void>}
|
|
225
|
-
*/
|
|
226
|
-
async clear () {
|
|
156
|
+
async clear(): Promise<void> {
|
|
227
157
|
log.debug('Clearing logcat logs from device');
|
|
228
158
|
try {
|
|
229
159
|
const args = [...this.adb.defaultArgs, 'logcat', '-c'];
|
|
230
160
|
await exec(this.adb.path, args);
|
|
231
161
|
} catch (err) {
|
|
232
|
-
|
|
162
|
+
const execErr = err as ExecError;
|
|
163
|
+
log.warn(`Failed to clear logcat logs: ${execErr.stderr || execErr.message}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private outputHandler(logLine: string, prefix: string = ''): void {
|
|
168
|
+
const timestamp = Date.now();
|
|
169
|
+
let recentIndex = -1;
|
|
170
|
+
for (const key of this.logs.keys()) {
|
|
171
|
+
recentIndex = key;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
this.logs.set(++recentIndex, [logLine, timestamp]);
|
|
175
|
+
if (this.listenerCount('output')) {
|
|
176
|
+
this.emit('output', toLogEntry(logLine, timestamp));
|
|
177
|
+
}
|
|
178
|
+
if (this.debug && (this.debugTrace || !TRACE_PATTERN.test(logLine))) {
|
|
179
|
+
log.debug(prefix + logLine);
|
|
233
180
|
}
|
|
234
181
|
}
|
|
235
182
|
}
|
|
236
183
|
|
|
237
184
|
export default Logcat;
|
|
185
|
+
|
|
186
|
+
// Private entities
|
|
187
|
+
|
|
188
|
+
type LogFormat = typeof SUPPORTED_FORMATS[number];
|
|
189
|
+
|
|
190
|
+
function requireFormat(format: string): LogFormat {
|
|
191
|
+
if (!SUPPORTED_FORMATS.includes(format as LogFormat)) {
|
|
192
|
+
log.info(`The format value '${format}' is unknown. Supported values are: ${SUPPORTED_FORMATS}`);
|
|
193
|
+
log.info(`Defaulting to '${DEFAULT_FORMAT}'`);
|
|
194
|
+
return DEFAULT_FORMAT;
|
|
195
|
+
}
|
|
196
|
+
return format as LogFormat;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function toLogEntry(message: string, timestamp: number): LogEntry {
|
|
200
|
+
return {
|
|
201
|
+
timestamp,
|
|
202
|
+
level: 'ALL',
|
|
203
|
+
message,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function requireSpec(spec: string): string {
|
|
208
|
+
const [tag, priority] = spec.split(':');
|
|
209
|
+
let resultTag = tag;
|
|
210
|
+
if (!resultTag) {
|
|
211
|
+
log.info(`The tag value in spec '${spec}' cannot be empty`);
|
|
212
|
+
log.info(`Defaulting to '${DEFAULT_TAG}'`);
|
|
213
|
+
resultTag = DEFAULT_TAG;
|
|
214
|
+
}
|
|
215
|
+
if (!priority) {
|
|
216
|
+
log.info(`The priority value in spec '${spec}' is empty. Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
217
|
+
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
218
|
+
}
|
|
219
|
+
if (!SUPPORTED_PRIORITIES.some((p) => _.toLower(priority) === _.toLower(p))) {
|
|
220
|
+
log.info(`The priority value in spec '${spec}' is unknown. Supported values are: ${SUPPORTED_PRIORITIES}`);
|
|
221
|
+
log.info(`Defaulting to Verbose (${DEFAULT_PRIORITY})`);
|
|
222
|
+
return `${resultTag}:${DEFAULT_PRIORITY}`;
|
|
223
|
+
}
|
|
224
|
+
return spec;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function formatFilterSpecs(filterSpecs: string | string[]): string[] {
|
|
228
|
+
if (!_.isArray(filterSpecs)) {
|
|
229
|
+
filterSpecs = [filterSpecs];
|
|
230
|
+
}
|
|
231
|
+
return filterSpecs
|
|
232
|
+
.filter((spec) => spec && _.isString(spec) && !spec.startsWith('-'))
|
|
233
|
+
.map((spec) => spec.includes(':') ? requireSpec(spec) : spec);
|
|
234
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-adb",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.3",
|
|
4
4
|
"description": "Android Debug Bridge interface",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"conventional-changelog-conventionalcommits": "^9.0.0",
|
|
80
80
|
"mocha": "^11.0.1",
|
|
81
81
|
"prettier": "^3.0.0",
|
|
82
|
-
"semantic-release": "^25.0.
|
|
82
|
+
"semantic-release": "^25.0.2",
|
|
83
83
|
"ts-node": "^10.9.1",
|
|
84
84
|
"typescript": "^5.4.2"
|
|
85
85
|
},
|