|
2 | 2 | "use strict";
|
3 | 3 |
|
4 | 4 | export class DeviceLogProvider implements Mobile.IDeviceLogProvider {
|
5 |
| - constructor(private $logger: ILogger) { } |
| 5 | + //sample line is "I/Web Console( 4438): Received Event: deviceready at file:///storage/emulated/0/Icenium/com.telerik.TestApp/js/index.js:48" |
| 6 | + private static LINE_REGEX = /.\/(.+?)\s*\(\s*(\d+?)\): (.*)/; |
6 | 7 |
|
7 |
| - public logData(line: string, platform: string, deviceIdentifier: string): void { |
8 |
| - this.$logger.out(line); |
| 8 | + constructor(private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, |
| 9 | + private $logger: ILogger) { } |
| 10 | + |
| 11 | + public logData(lineText: string, platform: string, deviceIdentifier: string): void { |
| 12 | + if (!platform || platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) { |
| 13 | + this.$logger.out(lineText); |
| 14 | + } else if (platform === this.$devicePlatformsConstants.Android) { |
| 15 | + let log = this.getConsoleLogFromLine(lineText); |
| 16 | + if (log) { |
| 17 | + if (log.tag) { |
| 18 | + this.$logger.out(`${log.tag}: ${log.message}`); |
| 19 | + } else { |
| 20 | + this.$logger.out(log.message); |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + private getConsoleLogFromLine(lineText: String): any { |
| 27 | + let acceptedTags = ["chromium", "Web Console", "JS"]; |
| 28 | + let match = lineText.match(DeviceLogProvider.LINE_REGEX); |
| 29 | + if (match) { |
| 30 | + if(acceptedTags.indexOf(match[1]) !== -1) { |
| 31 | + return {tag: match[1], message: match[3]}; |
| 32 | + } |
| 33 | + } else if (_.any(acceptedTags, (tag: string) => { return lineText.indexOf(tag) !== -1; })) { |
| 34 | + return {message: match[3]}; |
| 35 | + } |
| 36 | + return null; |
9 | 37 | }
|
10 | 38 | }
|
11 | 39 | $injector.register("deviceLogProvider", DeviceLogProvider);
|
0 commit comments