Skip to content

Commit a51122b

Browse files
authored
Merge pull request #3941 from NativeScript/kddimitrov/make-log-parser-generic
feat: make log parser logic to work with multiple rules
2 parents 85b1a52 + ee2f0e5 commit a51122b

18 files changed

+238
-270
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ $injector.requireCommand("resources|generate|splashes", "./commands/generate-ass
176176
$injector.requirePublic("assetsGenerationService", "./services/assets-generation/assets-generation-service");
177177

178178
$injector.require("filesHashService", "./services/files-hash-service");
179-
$injector.require("iOSLogParserService", "./services/ios-log-parser-service");
179+
$injector.require("logParserService", "./services/log-parser-service");
180180
$injector.require("iOSDebuggerPortService", "./services/ios-debugger-port-service");
181181

182182
$injector.require("pacoteService", "./services/pacote-service");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DeviceLogProviderBase } from "../mobile/device-log-provider-base";
2+
import { DEVICE_LOG_EVENT_NAME } from "../constants";
23

34
export class DeviceLogProvider extends DeviceLogProviderBase {
45
constructor(protected $logFilter: Mobile.ILogFilter,
@@ -15,6 +16,7 @@ export class DeviceLogProvider extends DeviceLogProviderBase {
1516

1617
if (data) {
1718
this.emit('data', deviceIdentifier, data);
19+
this.emit(DEVICE_LOG_EVENT_NAME, data, deviceIdentifier);
1820
}
1921
}
2022

lib/common/commands/device/device-log-stream.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { IOS_LOG_PREDICATE } from "../../constants";
2+
13
export class OpenDeviceLogStreamCommand implements ICommand {
24
private static NOT_SPECIFIED_DEVICE_ERROR_MESSAGE = "More than one device found. Specify device explicitly.";
35

@@ -23,7 +25,7 @@ export class OpenDeviceLogStreamCommand implements ICommand {
2325
this.$errors.fail(OpenDeviceLogStreamCommand.NOT_SPECIFIED_DEVICE_ERROR_MESSAGE);
2426
}
2527

26-
const action = (device: Mobile.IiOSDevice) => device.openDeviceLogStream({predicate: 'senderImagePath contains "NativeScript"'});
28+
const action = (device: Mobile.IiOSDevice) => device.openDeviceLogStream({predicate: IOS_LOG_PREDICATE});
2729
await this.$devicesService.execute(action);
2830
}
2931
}

lib/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class EmulatorDiscoveryNames {
5959
}
6060

6161
export const DEVICE_LOG_EVENT_NAME = "deviceLogData";
62+
export const IOS_LOG_PREDICATE = 'senderImagePath contains "NativeScript" || eventMessage contains[c] "NativeScript"';
6263

6364
export const TARGET_FRAMEWORK_IDENTIFIERS = {
6465
Cordova: "Cordova",

lib/common/definitions/mobile.d.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ declare module Mobile {
186186
/**
187187
* Describes methods for providing device logs to a specific consumer.
188188
*/
189-
interface IDeviceLogProvider {
189+
interface IDeviceLogProvider extends NodeJS.EventEmitter {
190190
/**
191191
* Logs data in the specific way for the consumer.
192192
* @param {string} line String from the device logs.
@@ -248,12 +248,6 @@ declare module Mobile {
248248
* @param {Mobile.IiOSLogStreamOptions} options Describes the options which can be passed
249249
*/
250250
startLogProcess(deviceId: string, options?: Mobile.IiOSLogStreamOptions): Promise<void>;
251-
/**
252-
* Starts a new process for getting simulator logs and emits and DEVICE_LOG_EVENT_NAME event. The event's reponse is with muted=true flag so it will not be printed from deviceLogProvider.
253-
* @param {string} deviceId The unique identifier of the device.
254-
* @param {Mobile.IiOSLogStreamOptions} options Describes the options which can be passed
255-
*/
256-
startNewMutedLogProcess(deviceId: string, options?: Mobile.IiOSLogStreamOptions): Promise<void>;
257251
}
258252

259253
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DeviceLogProviderBase } from "./device-log-provider-base";
2+
import { DEVICE_LOG_EVENT_NAME } from "../constants";
23

34
export class DeviceLogProvider extends DeviceLogProviderBase {
45
constructor(protected $logFilter: Mobile.ILogFilter,
@@ -11,6 +12,7 @@ export class DeviceLogProvider extends DeviceLogProviderBase {
1112
const data = this.$logFilter.filterData(platform, lineText, loggingOptions);
1213
if (data) {
1314
this.$logger.write(data);
15+
this.emit(DEVICE_LOG_EVENT_NAME, lineText, deviceIdentifier);
1416
}
1517
}
1618

lib/common/mobile/ios/simulator/ios-simulator-application-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from "path";
33
import * as temp from "temp";
44
import { hook, getPidFromiOSSimulatorLogs } from "../../../helpers";
55
import { cache } from "../../../decorators";
6+
import { IOS_LOG_PREDICATE } from "../../../constants";
67

78
export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
89
constructor(private iosSim: any,
@@ -104,6 +105,6 @@ export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
104105

105106
@cache()
106107
private startDeviceLog(): Promise<void> {
107-
return this.device.openDeviceLogStream({predicate: 'senderImagePath contains "NativeScript"'});
108+
return this.device.openDeviceLogStream({predicate: IOS_LOG_PREDICATE});
108109
}
109110
}

lib/common/mobile/ios/simulator/ios-simulator-device.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import { cache } from "../../../decorators";
66
export class IOSSimulator implements Mobile.IiOSSimulator {
77
private _applicationManager: Mobile.IDeviceApplicationManager;
88
private _fileSystem: Mobile.IDeviceFileSystem;
9-
private _deviceLogHandler: Function;
109

1110
constructor(private simulator: Mobile.IiSimDevice,
1211
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
13-
private $deviceLogProvider: Mobile.IDeviceLogProvider,
1412
private $injector: IInjector,
1513
private $iOSSimResolver: Mobile.IiOSSimResolver,
1614
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider) { }
@@ -57,20 +55,6 @@ export class IOSSimulator implements Mobile.IiOSSimulator {
5755

5856
@cache()
5957
public async openDeviceLogStream(options?: Mobile.IiOSLogStreamOptions): Promise<void> {
60-
this._deviceLogHandler = this.onDeviceLog.bind(this, options);
61-
this.$iOSSimulatorLogProvider.on(constants.DEVICE_LOG_EVENT_NAME, this._deviceLogHandler);
6258
return this.$iOSSimulatorLogProvider.startLogProcess(this.simulator.id, options);
6359
}
64-
65-
public detach(): void {
66-
if (this._deviceLogHandler) {
67-
this.$iOSSimulatorLogProvider.removeListener(constants.DEVICE_LOG_EVENT_NAME, this._deviceLogHandler);
68-
}
69-
}
70-
71-
private onDeviceLog(options: Mobile.IiOSLogStreamOptions, response: IOSDeviceLib.IDeviceLogData): void {
72-
if (response.deviceId === this.deviceInfo.identifier && !(<any>response).muted) {
73-
this.$deviceLogProvider.logData(response.message, this.$devicePlatformsConstants.iOS, this.deviceInfo.identifier);
74-
}
75-
}
7660
}

lib/common/mobile/ios/simulator/ios-simulator-log-provider.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChildProcess } from "child_process";
2-
import { DEVICE_LOG_EVENT_NAME } from "../../../constants";
32
import { EventEmitter } from "events";
43

54
export class IOSSimulatorLogProvider extends EventEmitter implements Mobile.IiOSSimulatorLogProvider, IDisposable, IShouldDispose {
@@ -9,7 +8,9 @@ export class IOSSimulatorLogProvider extends EventEmitter implements Mobile.IiOS
98

109
constructor(private $iOSSimResolver: Mobile.IiOSSimResolver,
1110
private $logger: ILogger,
12-
private $processService: IProcessService) {
11+
private $processService: IProcessService,
12+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
13+
private $deviceLogProvider: Mobile.IDeviceLogProvider) {
1314
super();
1415
this.shouldDispose = true;
1516
}
@@ -24,7 +25,7 @@ export class IOSSimulatorLogProvider extends EventEmitter implements Mobile.IiOS
2425

2526
const action = (data: NodeBuffer | string) => {
2627
const message = data.toString();
27-
this.emit(DEVICE_LOG_EVENT_NAME, { deviceId, message, muted: (options || {}).muted });
28+
this.$deviceLogProvider.logData(message, this.$devicePlatformsConstants.iOS, deviceId);
2829
};
2930

3031
if (deviceLogChildProcess) {
@@ -53,14 +54,6 @@ export class IOSSimulatorLogProvider extends EventEmitter implements Mobile.IiOS
5354
}
5455
}
5556

56-
public async startNewMutedLogProcess(deviceId: string, options?: Mobile.IiOSLogStreamOptions): Promise<void> {
57-
options = options || {};
58-
options.muted = true;
59-
this.simulatorsLoggingEnabled[deviceId] = false;
60-
await this.startLogProcess(deviceId, options);
61-
this.simulatorsLoggingEnabled[deviceId] = false;
62-
}
63-
6457
public dispose(signal?: any) {
6558
if (this.shouldDispose) {
6659
_.each(this.simulatorsLogProcess, (logProcess: ChildProcess, deviceId: string) => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* tslint:disable:no-empty */
22

33
import * as util from "util";
4+
import { EventEmitter } from "events";
45

56
export class CommonLoggerStub implements ILogger {
67
setLevel(level: string): void { }
@@ -146,7 +147,7 @@ export class LogcatHelperStub implements Mobile.ILogcatHelper {
146147
}
147148
}
148149

149-
export class DeviceLogProviderStub implements Mobile.IDeviceLogProvider {
150+
export class DeviceLogProviderStub extends EventEmitter implements Mobile.IDeviceLogProvider {
150151
public logger = new CommonLoggerStub();
151152
public currentDevicePids: IStringDictionary = {};
152153
public currentDeviceProjectNames: IStringDictionary = {};

0 commit comments

Comments
 (0)