Skip to content

Commit 0f9709f

Browse files
Merge pull request #59 from telerik/vladimirov/fix-logs
Fix filtering of iOS Simulator logs per pid of new process
2 parents 838ed3f + 6a7ba38 commit 0f9709f

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ios-sim-portable",
3-
"version": "1.0.21",
3+
"version": "1.0.22",
44
"description": "",
55
"main": "./lib/ios-sim.js",
66
"scripts": {

0 commit comments

Comments
 (0)