Skip to content

Commit b4ffe76

Browse files
Fix ios logs with logLevel INFO (#2843)
Whenever an ios device log is triggered with logLevel INFO `console.log` statements are not seen on the console for ios 8 and ios 9 devices due to a difference in their formats. Fix this and add tests.
1 parent 31f8c94 commit b4ffe76

File tree

3 files changed

+135
-5
lines changed

3 files changed

+135
-5
lines changed

lib/nativescript-cli-lib-bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ $injector.requirePublicClass("deviceEmitter", "./common/appbuilder/device-emitte
1010
$injector.requirePublicClass("deviceLogProvider", "./common/appbuilder/device-log-provider");
1111
$injector.requirePublicClass("localBuildService", "./services/local-build-service");
1212
$injector.requirePublicClass("debugService", "./services/debug-service");
13-
$injector.require("iOSLogFilter", "./common/mobile/ios/ios-log-filter");
1413

1514
// We need this because some services check if (!$options.justlaunch) to start the device log after some operation.
1615
// We don't want this behaviour when the CLI is required as library.

lib/services/ios-log-filter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { cache } from "../common/decorators";
44
import * as iOSLogFilterBase from "../common/mobile/ios/ios-log-filter";
55

66
export class IOSLogFilter extends iOSLogFilterBase.IOSLogFilter implements Mobile.IPlatformLogFilter {
7-
protected infoFilterRegex = /^.*?(<Notice>:.*?((CONSOLE LOG|JS ERROR).*?)|(<Warning>:.*?)|(<Error>:.*?))$/im;
7+
protected infoFilterRegex = /^.*?(<Notice>:.*?(((?:CONSOLE|JS) (?:LOG|ERROR)).*?))$/im;
88

99
private partialLine: string = null;
1010

1111
constructor($loggingLevels: Mobile.ILoggingLevels,
1212
private $fs: IFileSystem,
1313
private $projectData: IProjectData) {
14-
super($loggingLevels);
15-
}
14+
super($loggingLevels);
15+
}
1616

1717
public filterData(data: string, logLevel: string, pid?: string): string {
18-
data = super.filterData(data, logLevel, pid);
18+
data = super.filterData(data, logLevel, pid);
1919
if (pid && data && data.indexOf(`[${pid}]`) === -1) {
2020
return null;
2121
}

test/services/ios-log-filter.ts

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { IOSLogFilter } from "../../lib/services/ios-log-filter";
2+
import { Yok } from "../../lib/common/yok";
3+
import { LoggingLevels } from "../../lib/common/mobile/logging-levels";
4+
import * as assert from "assert";
5+
6+
function createTestInjector(): IInjector {
7+
const testInjector = new Yok();
8+
testInjector.register("loggingLevels", LoggingLevels);
9+
testInjector.register("fs", {
10+
exists: () => false
11+
});
12+
testInjector.register("projectData", {
13+
initializeProjectData: () => { /* empty */ },
14+
projectDir: "test"
15+
});
16+
17+
return testInjector;
18+
}
19+
20+
describe("iOSLogFilter", () => {
21+
let testInjector: IInjector;
22+
let logFilter: Mobile.IPlatformLogFilter;
23+
const testData = [
24+
{
25+
version: 9,
26+
originalDataArr: [
27+
"May 24 15:54:38 Dragons-iPhone backboardd(BaseBoard)[62] <Error>: Unable to bootstrap_look_up port with name .gsEvents: unknown error code (1102)",
28+
"May 24 15:54:51 Dragons-iPhone locationd[67] <Notice>: Client com.apple.springboard disconnected",
29+
"May 24 14:44:59 iPad-90 NativeScript250[790] <Notice>: CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
30+
"May 24 14:44:59 iPad-90 NativeScript250[790] <Notice>: CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
31+
"May 24 14:44:59 iPad-90 mobile_installation_proxy[355] <Error>: 0x1f197000 LoadInfoPlist: Failed to create CFBundle from URL file:///private/var/mobile/Containers/Bundle/Application/EB4866CC-25D2-4A3B-AA6C-70FFA08B908E/NativeScript143.app",
32+
"May 24 14:44:59 iPad-90 mobile_installation_proxy[355] <Error>: 0x1f197000 LoadInfoPlist: Failed to create CFBundle from URL file:///private/var/mobile/Containers/Bundle/Application/0DA02818-DCAE-407C-979D-D55F4F36F8D2/NativeScript300.app",
33+
" May 24 14:44:59 iPad-90 mobile_installation_proxy[355] <Error>: 0x1f197000 LoadInfoPlist: Failed to create CFBundle from URL file:///private/var/mobile/Containers/Bundle/Application/B0EE9362-7BDD-4FF2-868F-857B76D9D8D3/Cordova370.app",
34+
" May 24 14:44:59 iPad-90 NativeScript250[790] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION",
35+
""
36+
],
37+
infoExpectedArr: [
38+
null,
39+
null,
40+
"CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
41+
"CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
42+
null,
43+
null,
44+
null,
45+
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION",
46+
null
47+
]
48+
},
49+
{
50+
version: 10,
51+
originalDataArr: [
52+
"May 24 15:54:52 Dragons-iPhone apsd(PersistentConnection)[90] <Notice>: 2017-05-24 15:54:52 +0300 apsd[90]: <PCDispatchTimer: 0x156ad240> performing call back",
53+
"May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
54+
"May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION",
55+
" May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:",
56+
" May 24 15:54:52 Dragons-iPhone NativeScript250(NativeScript)[356] <Notice>: CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3478:36: resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:416:40",
57+
"resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:401:31",
58+
"file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:449:31",
59+
"invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:223:42",
60+
"onInvokeTask@file:///app/tns_modules/@angular/core/bundles/core.umd.js:4382:51",
61+
"invokeTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:222:54",
62+
"runTask@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:123:57",
63+
"drainMicroTaskQueue@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:355:42",
64+
"promiseReactionJob@[native code]",
65+
"UIApplicationMain@[native code]",
66+
"start@file:///app/tns_modules/tns-core-modules/application/application.js:251:26",
67+
"bootstrapApp@file:///app/tns_module",
68+
""
69+
],
70+
infoExpectedArr: [
71+
null,
72+
"CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG",
73+
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3472:32: EXCEPTION: Uncaught (in promise): Error: CUSTOM EXCEPTION",
74+
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3477:36: ORIGINAL STACKTRACE:",
75+
"CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:3478:36: resolvePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:416:40",
76+
null,
77+
null,
78+
null,
79+
null,
80+
null,
81+
null,
82+
null,
83+
null,
84+
null,
85+
null,
86+
null,
87+
null
88+
]
89+
}
90+
];
91+
const infoLogLevel = "INFO";
92+
const fullLogLevel = "FULL";
93+
94+
beforeEach(() => {
95+
testInjector = createTestInjector();
96+
logFilter = testInjector.resolve(IOSLogFilter);
97+
});
98+
99+
describe("filterData", () => {
100+
testData.forEach(data => {
101+
it(`returns correct data when logLevel is ${fullLogLevel} on iOS ${data.version} and all data is passed at once`, () => {
102+
const actualData = logFilter.filterData(data.originalDataArr.join("\n"), fullLogLevel, null);
103+
const actualArr = actualData.split("\n").map(line => line.trim());
104+
const expectedArr = data.originalDataArr.map(line => line.trim());
105+
assert.deepEqual(actualArr, expectedArr);
106+
});
107+
108+
it(`returns correct data when logLevel is ${fullLogLevel} on iOS ${data.version} and data is passed one line at a time`, () => {
109+
data.originalDataArr.forEach(line => {
110+
const actualData = logFilter.filterData(line, fullLogLevel, null);
111+
assert.deepEqual(actualData.trim(), line.trim());
112+
});
113+
});
114+
115+
it(`parses data incorrectly when logLevel is ${infoLogLevel} on iOS ${data.version} and all data is passed at once`, () => {
116+
const actualData = logFilter.filterData(data.originalDataArr.join("\n"), infoLogLevel, null);
117+
const actualArr = actualData.split("\n").map(line => line.trim());
118+
const expectedArr = ["CONSOLE LOG file:///app/modules/homeView/homeView.component.js:13:24: CUSTOM CONSOLE LOG", ""];
119+
assert.deepEqual(actualArr, expectedArr);
120+
});
121+
122+
it(`returns correct data when logLevel is ${infoLogLevel} on iOS ${data.version} and data is passed one line at a time`, () => {
123+
data.originalDataArr.forEach((line, index) => {
124+
const actualData = logFilter.filterData(line, infoLogLevel, null);
125+
const expectedData = data.infoExpectedArr[index];
126+
assert.deepEqual(actualData && actualData.trim(), expectedData && expectedData);
127+
});
128+
});
129+
});
130+
});
131+
});

0 commit comments

Comments
 (0)