Skip to content

Commit 32c0d43

Browse files
Add filtering for simulator logs
Add filtering for simulator logs based on the PID of the started process. In order to use the filtering, just pass the output of startApplication method as a second parameter of printDeviceLog method.
1 parent eb3dd35 commit 32c0d43

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

lib/declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface ISimulator {
5555
uninstallApplication(deviceId: string, appIdentifier: string): IFuture<void>;
5656
startApplication(deviceId: string, appIdentifier: string): IFuture<string>;
5757
stopApplication(deviceId: string, appIdentifier: string): IFuture<string>;
58-
printDeviceLog(deviceId: string): void;
58+
printDeviceLog(deviceId: string, launchResult?: string): void;
5959
startSimulator(): IFuture<void>;
6060
}
6161

lib/iphone-simulator-common.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,36 @@ export function getInstalledApplications(deviceId: string): IFuture<IApplication
3737
}).future<IApplication[]>()();
3838
}
3939

40-
export function printDeviceLog(deviceId: string): void {
40+
export function printDeviceLog(deviceId: string, launchResult?: string): void {
4141
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
42-
42+
let pid: string;
43+
if(launchResult) {
44+
pid = launchResult.split(":")[1].trim();
45+
}
4346
let childProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
4447
if (childProcess.stdout) {
4548
childProcess.stdout.on("data", (data: NodeBuffer) => {
46-
process.stdout.write(data.toString());
49+
let dataAsString = data.toString();
50+
if(pid) {
51+
if (dataAsString.indexOf(`[${pid}]`) > -1) {
52+
process.stdout.write(dataAsString);
53+
}
54+
} else {
55+
process.stdout.write(dataAsString);
56+
}
4757
});
4858
}
4959

5060
if (childProcess.stderr) {
5161
childProcess.stderr.on("data", (data: string) => {
62+
let dataAsString = data.toString();
63+
if(pid) {
64+
if (dataAsString.indexOf(`[${pid}]`) > -1) {
65+
process.stdout.write(dataAsString);
66+
}
67+
} else {
68+
process.stdout.write(dataAsString);
69+
}
5270
process.stdout.write(data.toString());
5371
});
5472
}

lib/iphone-simulator-xcode-6.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export class XCode6Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
8080
}
8181
}
8282

83-
public printDeviceLog(deviceId: string): void {
84-
common.printDeviceLog(deviceId);
83+
public printDeviceLog(deviceId: string, launchResult?: string): void {
84+
common.printDeviceLog(deviceId, launchResult);
8585
}
8686

8787
public startSimulator(): IFuture<void> {

lib/iphone-simulator-xcode-7.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,7 @@ export class XCode7Simulator implements ISimulator {
5454
let launchResult = this.simctl.launch(device.id, applicationIdentifier).wait();
5555

5656
if (options.logging) {
57-
let pid = launchResult.split(":")[1].trim();
58-
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", device.id, "system.log");
59-
60-
let childProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
61-
if(childProcess.stdout) {
62-
childProcess.stdout.on("data", (data: NodeBuffer) => {
63-
let dataAsString = data.toString();
64-
if (dataAsString.indexOf(`[${pid}]`) > -1) {
65-
process.stdout.write(dataAsString);
66-
}
67-
});
68-
}
69-
70-
if(childProcess.stderr) {
71-
childProcess.stderr.on("data", (data: string) => {
72-
let dataAsString = data.toString();
73-
if (dataAsString.indexOf(`[${pid}]`) > -1) {
74-
process.stdout.write(dataAsString);
75-
}
76-
});
77-
}
57+
this.printDeviceLog(device.id, launchResult);
7858
}
7959
}).future<void>()();
8060
}
@@ -117,8 +97,8 @@ export class XCode7Simulator implements ISimulator {
11797
}
11898
}
11999

120-
public printDeviceLog(deviceId: string): void {
121-
common.printDeviceLog(deviceId);
100+
public printDeviceLog(deviceId: string, launchResult?: string): void {
101+
common.printDeviceLog(deviceId, launchResult);
122102
}
123103

124104
private getDeviceToRun(): IFuture<IDevice> {

0 commit comments

Comments
 (0)