Skip to content

Commit 8f6f8e9

Browse files
committed
fix(debug-ios): start log process on tns debug ios --justlaunch command
1 parent e61068c commit 8f6f8e9

File tree

5 files changed

+47
-21
lines changed

5 files changed

+47
-21
lines changed

lib/common/definitions/mobile.d.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ declare module Mobile {
143143
--predicate 'eventType == logEvent and subsystem contains "com.example.my_subsystem"'
144144
*/
145145
predicate?: string;
146-
/**
147-
* If set to true, device's log will not be displayed on the console.
148-
*/
149-
muted?: boolean;
150146
}
151147

152148
interface IDeviceAppData extends IPlatform, IConnectTimeoutOption {
@@ -221,12 +217,18 @@ declare module Mobile {
221217
* @param {string} projectName The project name of the currently running application for which we need the logs.
222218
*/
223219
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void;
220+
221+
/**
222+
* Disables logs on the specified device and does not print any logs on the console.
223+
* @param {string} deviceIdentifier The unique identifier of the device.
224+
*/
225+
muteLogsForDevice(deviceIdentifier: string): void;
224226
}
225227

226228
/**
227229
* Describes different options for filtering device logs.
228230
*/
229-
interface IDeviceLogOptions extends IStringDictionary {
231+
interface IDeviceLogOptions extends IDictionary<string | boolean> {
230232
/**
231233
* Process id of the application on the device.
232234
*/
@@ -241,6 +243,11 @@ declare module Mobile {
241243
* The project name.
242244
*/
243245
projectName?: string;
246+
247+
/**
248+
* Specifies if the logs will be printed on the console.
249+
*/
250+
muteLogs?: boolean;
244251
}
245252

246253
/**

lib/common/mobile/device-log-provider-base.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export abstract class DeviceLogProviderBase extends EventEmitter implements Mobi
2626
this.setLogLevel(logLevel, deviceIdentifier);
2727
}
2828

29+
public muteLogsForDevice(deviceIdentifier: string): void {
30+
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.muteLogs, true);
31+
}
32+
2933
protected getApplicationPidForDevice(deviceIdentifier: string): string {
3034
return this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].applicationPid;
3135
}
@@ -39,7 +43,7 @@ export abstract class DeviceLogProviderBase extends EventEmitter implements Mobi
3943
return this.devicesLogOptions[deviceIdentifier];
4044
}
4145

42-
protected setDeviceLogOptionsProperty(deviceIdentifier: string, propNameFunction: Function, propertyValue: string): void {
46+
protected setDeviceLogOptionsProperty(deviceIdentifier: string, propNameFunction: Function, propertyValue: string | boolean): void {
4347
const propertyName = getPropertyName(propNameFunction);
4448

4549
if (propertyName) {

lib/common/mobile/device-log-provider.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@ export class DeviceLogProvider extends DeviceLogProviderBase {
1111
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier);
1212
const data = this.$logFilter.filterData(platform, lineText, loggingOptions);
1313
if (data) {
14-
this.$logger.write(data);
14+
this.logDataCore(data, loggingOptions);
1515
this.emit(DEVICE_LOG_EVENT_NAME, lineText, deviceIdentifier, platform);
1616
}
1717
}
1818

1919
public setLogLevel(logLevel: string, deviceIdentifier?: string): void {
2020
this.$logFilter.loggingLevel = logLevel.toUpperCase();
2121
}
22+
23+
private logDataCore(data: string, loggingOptions: Mobile.IDeviceLogOptions): void {
24+
if (!loggingOptions || (loggingOptions && !loggingOptions.muteLogs)) {
25+
this.$logger.write(data);
26+
}
27+
}
2228
}
2329
$injector.register("deviceLogProvider", DeviceLogProvider);

lib/common/test/unit-tests/stubs.ts

+2
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,6 @@ export class DeviceLogProviderStub extends EventEmitter implements Mobile.IDevic
171171
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void {
172172
this.currentDeviceProjectNames[deviceIdentifier] = projectName;
173173
}
174+
175+
muteLogsForDevice(deviceIdentifier: string): void { }
174176
}

lib/services/ios-debug-service.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
5050
debugOptions.emulator = true;
5151
}
5252

53-
if (!debugOptions.justlaunch) {
54-
let projectName = debugData.projectName;
55-
if (!projectName && debugData.projectDir) {
56-
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
57-
projectName = projectData.projectName;
58-
}
59-
60-
if (projectName) {
61-
this.$deviceLogProvider.setProjectNameForDevice(debugData.deviceIdentifier, projectName);
62-
}
63-
64-
await this.device.openDeviceLogStream({ predicate: IOS_LOG_PREDICATE });
65-
}
66-
53+
await this.startDeviceLogProcess(debugData, debugOptions);
6754
await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(this.device, debugData, debugOptions);
6855

6956
if (debugOptions.emulator) {
@@ -113,6 +100,26 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
113100
return chromeDebugUrl;
114101
}
115102

103+
private async startDeviceLogProcess(debugData: IDebugData, debugOptions: IDebugOptions): Promise<void> {
104+
if (debugOptions.justlaunch) {
105+
// No logs should be printed on console when `--justlaunch` option is passed.
106+
// On the other side we need to start log process in order to get debugger port from logs.
107+
this.$deviceLogProvider.muteLogsForDevice(debugData.deviceIdentifier);
108+
}
109+
110+
let projectName = debugData.projectName;
111+
if (!projectName && debugData.projectDir) {
112+
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
113+
projectName = projectData.projectName;
114+
}
115+
116+
if (projectName) {
117+
this.$deviceLogProvider.setProjectNameForDevice(debugData.deviceIdentifier, projectName);
118+
}
119+
120+
await this.device.openDeviceLogStream({ predicate: IOS_LOG_PREDICATE });
121+
}
122+
116123
private async killProcess(childProcess: ChildProcess): Promise<void> {
117124
if (childProcess) {
118125
return new Promise<void>((resolve, reject) => {

0 commit comments

Comments
 (0)