Skip to content

Commit f9a812e

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

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
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

+12-11
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
131131
deviceLogChildProcess = this.getDeviceLogProcess(deviceId);
132132
if (deviceLogChildProcess.stdout) {
133133
deviceLogChildProcess.stdout.on("data", (data: NodeBuffer) => {
134-
let dataAsString = data.toString();
134+
const dataAsString = data.toString();
135+
135136
if (pid) {
136137
if (dataAsString.indexOf(`[${pid}]`) > -1 || dataAsString.indexOf(` ${pid} `) > -1) {
137138
process.stdout.write(dataAsString);
@@ -144,32 +145,32 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
144145

145146
if (deviceLogChildProcess.stderr) {
146147
deviceLogChildProcess.stderr.on("data", (data: string) => {
147-
let dataAsString = data.toString();
148+
const dataAsString = data.toString();
149+
148150
if (pid) {
149151
if (dataAsString.indexOf(`[${pid}]`) > -1 || dataAsString.indexOf(` ${pid} `) > -1) {
150152
process.stdout.write(dataAsString);
151153
}
152154
} else {
153155
process.stdout.write(dataAsString);
154156
}
155-
process.stdout.write(data.toString());
156157
});
157158
}
158159
}
159160

160161
return deviceLogChildProcess;
161162
}
162163

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];
167-
164+
public getDeviceLogProcess(deviceId: string, predicate?: string): any {
168165
if (!this.isDeviceLogOperationStarted) {
169-
if(majorVersion && parseInt(majorVersion) >= 11) {
170-
this.deviceLogChildProcess = this.simctl.getLog(deviceId);
166+
const device = this.getDeviceFromIdentifier(deviceId);
167+
const deviceVersion = device ? device.runtimeVersion : "";
168+
const majorVersion = deviceVersion.split(".")[0];
169+
170+
if (majorVersion && parseInt(majorVersion) >= 11) {
171+
this.deviceLogChildProcess = this.simctl.getLog(deviceId, predicate);
171172
} else {
172-
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
173+
const logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
173174
this.deviceLogChildProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
174175
}
175176

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): any {
125+
let predicateArgs: string[] = [];
126+
127+
if (!_.isUndefined(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)