Skip to content

fix: start log process on tns debug ios --justlaunch command #4078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/common/definitions/mobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ declare module Mobile {
--predicate 'eventType == logEvent and subsystem contains "com.example.my_subsystem"'
*/
predicate?: string;
/**
* If set to true, device's log will not be displayed on the console.
*/
muted?: boolean;
}

interface IDeviceAppData extends IPlatform, IConnectTimeoutOption {
Expand Down Expand Up @@ -221,12 +217,18 @@ declare module Mobile {
* @param {string} projectName The project name of the currently running application for which we need the logs.
*/
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void;

/**
* Disables logs on the specified device and does not print any logs on the console.
* @param {string} deviceIdentifier The unique identifier of the device.
*/
muteLogsForDevice(deviceIdentifier: string): void;
}

/**
* Describes different options for filtering device logs.
*/
interface IDeviceLogOptions extends IStringDictionary {
interface IDeviceLogOptions extends IDictionary<string | boolean> {
/**
* Process id of the application on the device.
*/
Expand All @@ -241,6 +243,11 @@ declare module Mobile {
* The project name.
*/
projectName?: string;

/**
* Specifies if the logs will be printed on the console.
*/
muteLogs?: boolean;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/common/mobile/device-log-provider-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export abstract class DeviceLogProviderBase extends EventEmitter implements Mobi
this.setLogLevel(logLevel, deviceIdentifier);
}

public muteLogsForDevice(deviceIdentifier: string): void {
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.muteLogs, true);
}

protected getApplicationPidForDevice(deviceIdentifier: string): string {
return this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].applicationPid;
}
Expand All @@ -39,7 +43,7 @@ export abstract class DeviceLogProviderBase extends EventEmitter implements Mobi
return this.devicesLogOptions[deviceIdentifier];
}

protected setDeviceLogOptionsProperty(deviceIdentifier: string, propNameFunction: Function, propertyValue: string): void {
protected setDeviceLogOptionsProperty(deviceIdentifier: string, propNameFunction: Function, propertyValue: string | boolean): void {
const propertyName = getPropertyName(propNameFunction);

if (propertyName) {
Expand Down
8 changes: 7 additions & 1 deletion lib/common/mobile/device-log-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ export class DeviceLogProvider extends DeviceLogProviderBase {
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier);
const data = this.$logFilter.filterData(platform, lineText, loggingOptions);
if (data) {
this.$logger.write(data);
this.logDataCore(data, loggingOptions);
this.emit(DEVICE_LOG_EVENT_NAME, lineText, deviceIdentifier, platform);
}
}

public setLogLevel(logLevel: string, deviceIdentifier?: string): void {
this.$logFilter.loggingLevel = logLevel.toUpperCase();
}

private logDataCore(data: string, loggingOptions: Mobile.IDeviceLogOptions): void {
if (!loggingOptions || (loggingOptions && !loggingOptions.muteLogs)) {
this.$logger.write(data);
}
}
}
$injector.register("deviceLogProvider", DeviceLogProvider);
2 changes: 2 additions & 0 deletions lib/common/test/unit-tests/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,6 @@ export class DeviceLogProviderStub extends EventEmitter implements Mobile.IDevic
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void {
this.currentDeviceProjectNames[deviceIdentifier] = projectName;
}

muteLogsForDevice(deviceIdentifier: string): void { }
}
35 changes: 21 additions & 14 deletions lib/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
debugOptions.emulator = true;
}

if (!debugOptions.justlaunch) {
let projectName = debugData.projectName;
if (!projectName && debugData.projectDir) {
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
projectName = projectData.projectName;
}

if (projectName) {
this.$deviceLogProvider.setProjectNameForDevice(debugData.deviceIdentifier, projectName);
}

await this.device.openDeviceLogStream({ predicate: IOS_LOG_PREDICATE });
}

await this.startDeviceLogProcess(debugData, debugOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be executed prior to await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEven..., because we depend on the logs to get the port.

await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(this.device, debugData, debugOptions);

if (debugOptions.emulator) {
Expand Down Expand Up @@ -113,6 +100,26 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
return chromeDebugUrl;
}

private async startDeviceLogProcess(debugData: IDebugData, debugOptions: IDebugOptions): Promise<void> {
if (debugOptions.justlaunch) {
// No logs should be printed on console when `--justlaunch` option is passed.
// On the other side we need to start log process in order to get debugger port from logs.
this.$deviceLogProvider.muteLogsForDevice(debugData.deviceIdentifier);
}

let projectName = debugData.projectName;
if (!projectName && debugData.projectDir) {
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
projectName = projectData.projectName;
}

if (projectName) {
this.$deviceLogProvider.setProjectNameForDevice(debugData.deviceIdentifier, projectName);
}

await this.device.openDeviceLogStream({ predicate: IOS_LOG_PREDICATE });
}

private async killProcess(childProcess: ChildProcess): Promise<void> {
if (childProcess) {
return new Promise<void>((resolve, reject) => {
Expand Down