Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit cffe2f8

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Don't duplicate the messages from logcat
Fixes NativeScript/nativescript-cli#1130
1 parent 2811f51 commit cffe2f8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mobile/android/logcat-helper.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
import byline = require("byline");
44

55
export class LogcatHelper implements Mobile.ILogcatHelper {
6+
private mapDeviceToLoggingStarted: IDictionary<boolean>;
7+
68
constructor(private $childProcess: IChildProcess,
79
private $deviceLogProvider: Mobile.IDeviceLogProvider,
810
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
911
private $logger: ILogger,
10-
private $staticConfig: Config.IStaticConfig) { }
12+
private $staticConfig: Config.IStaticConfig) {
13+
this.mapDeviceToLoggingStarted = Object.create(null);
14+
}
1115

1216
public start(deviceIdentifier: string): void {
13-
if(deviceIdentifier) {
17+
if (deviceIdentifier && !this.mapDeviceToLoggingStarted[deviceIdentifier]) {
1418
let adbPath = this.$staticConfig.getAdbFilePath().wait();
1519
// remove cached logs:
1620
this.$childProcess.spawnFromEvent(adbPath, ["-s", deviceIdentifier, "logcat", "-c"], "close", {}, {throwError: false}).wait();
@@ -22,6 +26,7 @@ export class LogcatHelper implements Mobile.ILogcatHelper {
2226
});
2327

2428
adbLogcat.on("close", (code: number) => {
29+
this.mapDeviceToLoggingStarted[deviceIdentifier] = false;
2530
if(code !== 0) {
2631
this.$logger.trace("ADB process exited with code " + code.toString());
2732
}
@@ -31,6 +36,8 @@ export class LogcatHelper implements Mobile.ILogcatHelper {
3136
let lineText = line.toString();
3237
this.$deviceLogProvider.logData(lineText, this.$devicePlatformsConstants.Android, deviceIdentifier);
3338
});
39+
40+
this.mapDeviceToLoggingStarted[deviceIdentifier] = true;
3441
}
3542
}
3643
}

0 commit comments

Comments
 (0)