Skip to content

Commit 56db899

Browse files
author
Kristian D. Dimitrov
committed
Fix comments for iOS11 Simulator log.
1 parent b4a9fdb commit 56db899

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

lib/declarations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface ISimctl {
3333
uninstall(deviceId: string, applicationIdentifier: string, opts?: any): void;
3434
notifyPost(deviceId: string, notification: string): void;
3535
getDevices(): IDevice[];
36-
getLog(deviceId: string): any;
36+
getLog(deviceId: string, predicate?: string): any;
3737
getAppContainer(deviceId: string, applicationIdentifier: string): string;
3838
}
3939

lib/iphone-simulator-xcode-simctl.ts

+23-29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use strict";
33

44
import childProcess = require("./child-process");
5+
import * as child_process from "child_process";
56
import errors = require("./errors");
67

78
import common = require("./iphone-simulator-common");
@@ -119,7 +120,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
119120
}
120121
}
121122

122-
public printDeviceLog(deviceId: string, launchResult?: string): any {
123+
public printDeviceLog(deviceId: string, launchResult?: string): child_process.ChildProcess {
123124
let pid = "";
124125
let deviceLogChildProcess;
125126

@@ -130,46 +131,39 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
130131
if (!this.isDeviceLogOperationStarted) {
131132
deviceLogChildProcess = this.getDeviceLogProcess(deviceId);
132133
if (deviceLogChildProcess.stdout) {
133-
deviceLogChildProcess.stdout.on("data", (data: NodeBuffer) => {
134-
let dataAsString = data.toString();
135-
if (pid) {
136-
if (dataAsString.indexOf(`[${pid}]`) > -1 || dataAsString.indexOf(` ${pid} `) > -1) {
137-
process.stdout.write(dataAsString);
138-
}
139-
} else {
140-
process.stdout.write(dataAsString);
141-
}
142-
});
134+
deviceLogChildProcess.stdout.on("data", this.logDataHandler.bind(this, pid));
143135
}
144136

145137
if (deviceLogChildProcess.stderr) {
146-
deviceLogChildProcess.stderr.on("data", (data: string) => {
147-
let dataAsString = data.toString();
148-
if (pid) {
149-
if (dataAsString.indexOf(`[${pid}]`) > -1 || dataAsString.indexOf(` ${pid} `) > -1) {
150-
process.stdout.write(dataAsString);
151-
}
152-
} else {
153-
process.stdout.write(dataAsString);
154-
}
155-
process.stdout.write(data.toString());
156-
});
138+
deviceLogChildProcess.stderr.on("data", this.logDataHandler.bind(this, pid));
157139
}
158140
}
159141

160142
return deviceLogChildProcess;
161143
}
162144

163-
public getDeviceLogProcess(deviceId: string): any {
164-
const device = this.getDeviceFromIdentifier(deviceId) || {};
165-
const deviceVersion = this.getDeviceFromIdentifier(deviceId).runtimeVersion || "";
166-
const majorVersion = deviceVersion.split(".")[0];
145+
private logDataHandler(pid: string, logData: NodeBuffer): void {
146+
const dataAsString = logData.toString();
167147

148+
if (pid) {
149+
if (dataAsString.indexOf(`[${pid}]`) > -1) {
150+
process.stdout.write(dataAsString);
151+
}
152+
} else {
153+
process.stdout.write(dataAsString);
154+
}
155+
}
156+
157+
public getDeviceLogProcess(deviceId: string, predicate?: string): child_process.ChildProcess {
168158
if (!this.isDeviceLogOperationStarted) {
169-
if(majorVersion && parseInt(majorVersion) >= 11) {
170-
this.deviceLogChildProcess = this.simctl.getLog(deviceId);
159+
const device = this.getDeviceFromIdentifier(deviceId);
160+
const deviceVersion = device ? device.runtimeVersion : "";
161+
const majorVersion = deviceVersion.split(".")[0];
162+
163+
if (majorVersion && parseInt(majorVersion) >= 11) {
164+
this.deviceLogChildProcess = this.simctl.getLog(deviceId, predicate);
171165
} else {
172-
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
166+
const logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
173167
this.deviceLogChildProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
174168
}
175169

lib/simctl.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ export class Simctl implements ISimctl {
121121
return devices;
122122
}
123123

124-
public getLog(deviceId: string): any {
125-
return this.simctlSpawn("spawn", [deviceId, "log", "stream"]);
124+
public getLog(deviceId: string, predicate?: string): child_process.ChildProcess {
125+
let predicateArgs: string[] = [];
126+
127+
if (predicate) {
128+
predicateArgs = ["--predicate", predicate];
129+
}
130+
131+
return this.simctlSpawn("spawn", [deviceId, "log", "stream", "--style", "syslog"].concat(predicateArgs));
126132
}
127133

128134
private simctlExec(command: string, args: string[], opts?: any): any {
@@ -133,7 +139,7 @@ export class Simctl implements ISimctl {
133139
return '';
134140
}
135141

136-
private simctlSpawn(command: string, args: string[], opts?: any): any {
142+
private simctlSpawn(command: string, args: string[], opts?: child_process.SpawnOptions): child_process.ChildProcess {
137143
return child_process.spawn("xcrun", ["simctl", command].concat(args), opts);
138144
}
139145
}

0 commit comments

Comments
 (0)