Skip to content

Commit 0278341

Browse files
Merge pull request #1232 from NativeScript/vladimirov/fix-android-logging
Fix device log for API 23
2 parents 97b0fd8 + c7ad91d commit 0278341

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/providers/device-log-provider.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
export class DeviceLogProvider implements Mobile.IDeviceLogProvider {
55
//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+
private static LINE_REGEX = /.\/(.+?)\s*\(\s*\d+?\): (.*)/;
7+
// sample line is "11-23 12:39:07.310 1584 1597 I art : Background sticky concurrent mark sweep GC freed 21966(1780KB) AllocSpace objects, 4(80KB) LOS objects, 77% free, 840KB/3MB, paused 4.018ms total 158.629ms"
8+
private static API_LEVEL_23_LINE_REGEX = /.+?\s+?(?:[A-Z]\s+?)([A-Za-z ]+?)\s+?\: (.*)/;
79

810
constructor(private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
911
private $logger: ILogger) { }
@@ -25,15 +27,12 @@ export class DeviceLogProvider implements Mobile.IDeviceLogProvider {
2527

2628
private getConsoleLogFromLine(lineText: String): any {
2729
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]};
30+
let match = lineText.match(DeviceLogProvider.LINE_REGEX) || lineText.match(DeviceLogProvider.API_LEVEL_23_LINE_REGEX);
31+
if (match && acceptedTags.indexOf(match[1].trim()) !== -1) {
32+
return {tag: match[1].trim(), message: match[2]};
3533
}
36-
return null;
34+
let matchingTag = _.any(acceptedTags, (tag: string) => { return lineText.indexOf(tag) !== -1; });
35+
return matchingTag ? { message: lineText } : null;
3736
}
3837
}
3938
$injector.register("deviceLogProvider", DeviceLogProvider);

0 commit comments

Comments
 (0)