-
-
Notifications
You must be signed in to change notification settings - Fork 197
Fix iOS11 Simulator logs #3145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix iOS11 Simulator logs #3145
Conversation
lib/services/ios-log-filter.ts
Outdated
@@ -16,7 +16,7 @@ export class IOSLogFilter extends iOSLogFilterBase.IOSLogFilter implements Mobil | |||
|
|||
public filterData(data: string, logLevel: string, pid?: string): string { | |||
data = super.filterData(data, logLevel, pid); | |||
if (pid && data && data.indexOf(`[${pid}]`) === -1) { | |||
if (pid && data && data.search(new RegExp(`[\\[\\s]${pid}[\\]\\s]`)) === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO either choose RegExp or indexOf for consistency in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used regex to avoid nested or complex "if" statements:
if(data && pid){
if(data.indexOf(` ${pid} `) || data.indexOf(`[${pid}]`)) {
}
}
or
if(data && pid && (data.indexOf(` ${pid} `) || data.indexOf(`[${pid}]`)) {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statement (data.indexOf(` ${pid} `) || data.indexOf(`[${pid}]`)
can be extracted into a separate method and called everywhere needed.
We'd avoid complexity and gain readability IMO
lib/services/ios-log-filter.ts
Outdated
line = line.substring(pidIndex + searchString.length, line.length); | ||
const pidIndex = line.indexOf(`[${pid}]`); | ||
const ios11PidIndex = line.indexOf(` ${pid} `); | ||
if (pidIndex > 0 || ios11PidIndex > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again choose either != 1
or > 0
for consistency in the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could change it to != -1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to use indexOf
because its a bit more fast in my opinion(didn't really compared performance tests though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit faster, but I made the suggestions just for consistency sake because IMO it's more important
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestions
This comment was marked as abuse.
This comment was marked as abuse.
lib/services/ios-log-filter.ts
Outdated
@@ -16,7 +16,7 @@ export class IOSLogFilter extends iOSLogFilterBase.IOSLogFilter implements Mobil | |||
|
|||
public filterData(data: string, logLevel: string, pid?: string): string { | |||
data = super.filterData(data, logLevel, pid); | |||
if (pid && data && data.indexOf(`[${pid}]`) === -1) { | |||
if (pid && data && data.search(new RegExp(`[\\[\\s]${pid}[\\]\\s]`)) === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statement (data.indexOf(` ${pid} `) || data.indexOf(`[${pid}]`)
can be extracted into a separate method and called everywhere needed.
We'd avoid complexity and gain readability IMO
lib/services/ios-log-filter.ts
Outdated
const pidIndex = line.indexOf(`[${pid}]`); | ||
const ios11PidIndex = line.indexOf(` ${pid} `); | ||
if (pidIndex > 0 || ios11PidIndex > 0) { | ||
const pidRegex = new RegExp(`.*[\\[\\s]{1}${pid}[\\s\\]]{1}.*?:(?:.*?\\(NativeScript\\) )*`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the part after :
in this RegExp
- I'm talking about the ignored capture group (?:.*?\\(NativeScript\\) )*
If one should wish to console.log
something like Loving (NativeScript) right now
in their application the log would appear as
"Aug 22 10:59:20 MCSOFAPPBLD TestApp[52946]: CONSOLE LOG file:///app/home/home-view-model.js:6:20: Loving (NativeScript) right now"
and the RegExp
would strip it to right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, will fix the regex.
} | ||
|
||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't match with neither pidIndex
nor ios11PidIndex
I do not believe we'd want to continue
.
I think this continue
statement should be returned in the previous block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking continue
outside the if
statement prevents lines that don't contain the pid to be logged.
This comment was marked as abuse.
This comment was marked as abuse.
@NathanaelA we are passing the predicate here, but we are still supporting older iOS versions as you can see here. For the older iOS versions we still need the filtration code. The benefit of the predicate is that the code that filters messages will be invoked only for NS messages, Moreover the regex is used only if the line contains the "pid" of the application. We haven't noticed any performance issues so far. The filtration of exception messages is not reproducible on Simulators, at least on my side. The real device logging and filtering is handled by different branch of the code. |
lib/services/ios-log-filter.ts
Outdated
if (pidIndex > 0) { | ||
line = line.substring(pidIndex + searchString.length, line.length); | ||
if (line.indexOf(`[${pid}]: `) !== -1) { | ||
const pidRegex = new RegExp(`.*[\\[]{1}${pid}[\\]]{1}(?::\\s(:?\\(NativeScript\\)\\s)*)`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RegExp
can be shortened to:
const pidRegex = new RegExp(`.*[\\[]${pid}[\\]]:\\s(:?\\(NativeScript\\)\\s)*`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this look as a final version:
const pidRegex = new RegExp(`^.*[\\[]${pid}[\\]]:\\s(?:\\(NativeScript\\)\\s)?`);
f51583e
to
6e2de8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks okay to me
Some tests would be nice
lib/services/ios-log-filter.ts
Outdated
if (pidIndex > 0) { | ||
line = line.substring(pidIndex + searchString.length, line.length); | ||
if (line.indexOf(`[${pid}]: `) !== -1) { | ||
const pidRegex = new RegExp(`^.*[\\[]${pid}[\\]]:\\s(?:\\(NativeScript\\)\\s)?`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually no need for [\\[]
and [\\]]
it can be further shortened to:
const pidRegex = new RegExp(`^.*\\[${pid}\\]:\\s(?:\\(NativeScript\\)\\s)?`);
run ci |
1 similar comment
run ci |
da5db06
to
2413d82
Compare
be0856a
to
6f87058
Compare
6f87058
to
a9a73a4
Compare
Part of the fix for #3141 (comment).
Log format for iOS 10.3: "Oct 3 19:07:55 machinename cliapp[15339]: CONSOLE LOG file:///app/main-view-model.js:18:20: Test Console fix..."
Log format for iOS 11: "2017-10-09 13:34:38.527844+0300 localhost cliapp[22235]: (NativeScript) CONSOLE LOG file:///app/main-view-model.js:18:20: Test Console fix.."
Needs NativeScript/ios-sim-portable#95 and telerik/mobile-cli-lib#1016