Skip to content

Commit 8d0dffc

Browse files
Fix filtering of iOS Simulator logs per pid of new process
When application is restarted, the PID of the process is changed. So when showing device logs, we should change the pid when the printDeviceLog is called. Spawn the process (`tail -f ...`) only one time, but change the PID whenever the method is called.
1 parent 838ed3f commit 8d0dffc

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

lib/iphone-simulator-common.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as os from "os";
99
import xcode = require("./xcode");
1010
let bplistParser = require("bplist-parser");
1111
let osenv = require("osenv");
12+
let isDeviceLogOperationStarted = false;
13+
let pid: string;
1214

1315
export function getInstalledApplications(deviceId: string): IFuture<IApplication[]> {
1416
return (() => {
@@ -38,37 +40,41 @@ export function getInstalledApplications(deviceId: string): IFuture<IApplication
3840
}
3941

4042
export function printDeviceLog(deviceId: string, launchResult?: string): void {
41-
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
42-
let pid: string;
4343
if(launchResult) {
4444
pid = launchResult.split(":")[1].trim();
4545
}
46-
let childProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
47-
if (childProcess.stdout) {
48-
childProcess.stdout.on("data", (data: NodeBuffer) => {
49-
let dataAsString = data.toString();
50-
if(pid) {
51-
if (dataAsString.indexOf(`[${pid}]`) > -1) {
46+
47+
if(!isDeviceLogOperationStarted) {
48+
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
49+
let childProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
50+
if (childProcess.stdout) {
51+
childProcess.stdout.on("data", (data: NodeBuffer) => {
52+
let dataAsString = data.toString();
53+
if(pid) {
54+
if (dataAsString.indexOf(`[${pid}]`) > -1) {
55+
process.stdout.write(dataAsString);
56+
}
57+
} else {
5258
process.stdout.write(dataAsString);
5359
}
54-
} else {
55-
process.stdout.write(dataAsString);
56-
}
57-
});
58-
}
60+
});
61+
}
5962

60-
if (childProcess.stderr) {
61-
childProcess.stderr.on("data", (data: string) => {
62-
let dataAsString = data.toString();
63-
if(pid) {
64-
if (dataAsString.indexOf(`[${pid}]`) > -1) {
63+
if (childProcess.stderr) {
64+
childProcess.stderr.on("data", (data: string) => {
65+
let dataAsString = data.toString();
66+
if(pid) {
67+
if (dataAsString.indexOf(`[${pid}]`) > -1) {
68+
process.stdout.write(dataAsString);
69+
}
70+
} else {
6571
process.stdout.write(dataAsString);
6672
}
67-
} else {
68-
process.stdout.write(dataAsString);
69-
}
70-
process.stdout.write(data.toString());
71-
});
73+
process.stdout.write(data.toString());
74+
});
75+
}
76+
77+
isDeviceLogOperationStarted = true;
7278
}
7379
}
7480

0 commit comments

Comments
 (0)