Skip to content

Commit 2c495c3

Browse files
author
Tsvetan Raikov
committed
Added CLI specific log filter for iOS
1 parent a21f61d commit 2c495c3

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

lib/bootstrap.ts

+2
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,5 @@ $injector.require("messages", "./common/messages/messages");
117117
$injector.require("xmlValidator", "./xml-validator");
118118

119119
$injector.requireCommand("devices", "./commands/devices");
120+
121+
$injector.require("iOSLogFilter", "./services/ios-log-filter");

lib/services/ios-log-filter.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export class IOSLogFilter implements Mobile.IPlatformLogFilter {
2+
3+
constructor(private $loggingLevels: Mobile.ILoggingLevels) { }
4+
5+
public filterData(data: string, logLevel: string, pid?: string): string {
6+
7+
if (pid && data && data.indexOf(`[${pid}]`) === -1) {
8+
return null;
9+
}
10+
11+
if (data) {
12+
if (data.indexOf("SecTaskCopyDebugDescription") !== -1 ||
13+
data.indexOf("NativeScript loaded bundle") !== -1 ||
14+
(data.indexOf("assertion failed:") !== -1 && data.indexOf("libxpc.dylib") !== -1)) {
15+
return null;
16+
}
17+
// CONSOLE LOG messages comme in the following form:
18+
// <date> <domain> <app>[pid] CONSOLE LOG file:///location:row:column: <actual message goes here>
19+
// This code removes the first part and leaves only the message as specified by the call to console.log function.
20+
// This removes the unnecessary information and makes the log consistent with Android.
21+
let logIndex = data.indexOf("CONSOLE LOG");
22+
if (logIndex !== -1) {
23+
let i = 4;
24+
while(i) { logIndex = data.indexOf(':', logIndex+1); i --; }
25+
if (logIndex > 0) {
26+
data = "JS:" + data.substring(logIndex+1, data.length);
27+
}
28+
}
29+
return data.trim();
30+
}
31+
32+
return data;
33+
}
34+
}
35+
$injector.register("iOSLogFilter", IOSLogFilter);

0 commit comments

Comments
 (0)