-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-simulator-log-provider.ts
64 lines (53 loc) · 2.18 KB
/
ios-simulator-log-provider.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { ChildProcess } from "child_process";
import { EventEmitter } from "events";
export class IOSSimulatorLogProvider extends EventEmitter implements Mobile.IiOSSimulatorLogProvider, IDisposable, IShouldDispose {
public shouldDispose: boolean;
private simulatorsLoggingEnabled: IDictionary<boolean> = {};
private simulatorsLogProcess: IDictionary<ChildProcess> = {};
constructor(private $iOSSimResolver: Mobile.IiOSSimResolver,
private $logger: ILogger,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $deviceLogProvider: Mobile.IDeviceLogProvider) {
super();
this.shouldDispose = true;
}
public setShouldDispose(shouldDispose: boolean) {
this.shouldDispose = shouldDispose;
}
public async startLogProcess(deviceId: string, options?: Mobile.IiOSLogStreamOptions): Promise<void> {
if (!this.simulatorsLoggingEnabled[deviceId]) {
const deviceLogChildProcess: ChildProcess = await this.$iOSSimResolver.iOSSim.getDeviceLogProcess(deviceId, options ? options.predicate : null);
const action = (data: NodeBuffer | string) => {
const message = data.toString();
this.$deviceLogProvider.logData(message, this.$devicePlatformsConstants.iOS, deviceId);
};
if (deviceLogChildProcess) {
deviceLogChildProcess.once("close", () => {
this.simulatorsLoggingEnabled[deviceId] = false;
});
deviceLogChildProcess.once("error", (err) => {
this.$logger.trace(`Error is thrown for device with identifier ${deviceId}. More info: ${err.message}.`);
this.simulatorsLoggingEnabled[deviceId] = false;
});
}
if (deviceLogChildProcess.stdout) {
deviceLogChildProcess.stdout.on("data", action.bind(this));
}
if (deviceLogChildProcess.stderr) {
deviceLogChildProcess.stderr.on("data", action.bind(this));
}
this.simulatorsLoggingEnabled[deviceId] = true;
this.simulatorsLogProcess[deviceId] = deviceLogChildProcess;
}
}
public dispose(signal?: any) {
if (this.shouldDispose) {
_.each(this.simulatorsLogProcess, (logProcess: ChildProcess, deviceId: string) => {
if (logProcess) {
logProcess.kill(signal);
}
});
}
}
}
$injector.register("iOSSimulatorLogProvider", IOSSimulatorLogProvider);