Skip to content

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

Merged
merged 4 commits into from
Oct 16, 2017
Merged

Fix iOS11 Simulator logs #3145

merged 4 commits into from
Oct 16, 2017

Conversation

KristianDD
Copy link
Contributor

@KristianDD KristianDD commented Oct 3, 2017

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

@KristianDD KristianDD self-assigned this Oct 3, 2017
@KristianDD KristianDD added the bug label Oct 3, 2017
@@ -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) {
Copy link
Contributor

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

Copy link
Contributor Author

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}]`)) {
}

Copy link
Contributor

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

line = line.substring(pidIndex + searchString.length, line.length);
const pidIndex = line.indexOf(`[${pid}]`);
const ios11PidIndex = line.indexOf(` ${pid} `);
if (pidIndex > 0 || ios11PidIndex > 0) {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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).

Copy link
Contributor

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

Copy link
Contributor

@Plamen5kov Plamen5kov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestions

@NathanaelA

This comment was marked as abuse.

@@ -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) {
Copy link
Contributor

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

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\\) )*`);
Copy link
Contributor

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

Copy link
Contributor Author

@KristianDD KristianDD Oct 9, 2017

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;
Copy link
Contributor

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

Copy link
Contributor Author

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.

@NathanaelA

This comment was marked as abuse.

@KristianDD
Copy link
Contributor Author

@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.

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)*)`);
Copy link
Contributor

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)*`);

Copy link
Contributor Author

@KristianDD KristianDD Oct 11, 2017

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)?`);

@KristianDD KristianDD force-pushed the kddimitrov/ios-11-log branch from f51583e to 6e2de8a Compare October 11, 2017 12:55
Copy link
Contributor

@Mitko-Kerezov Mitko-Kerezov left a 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

if (pidIndex > 0) {
line = line.substring(pidIndex + searchString.length, line.length);
if (line.indexOf(`[${pid}]: `) !== -1) {
const pidRegex = new RegExp(`^.*[\\[]${pid}[\\]]:\\s(?:\\(NativeScript\\)\\s)?`);
Copy link
Contributor

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)?`);

@dtopuzov
Copy link
Contributor

run ci

1 similar comment
@dtopuzov
Copy link
Contributor

run ci

@KristianDD KristianDD force-pushed the kddimitrov/ios-11-log branch from da5db06 to 2413d82 Compare October 13, 2017 11:21
@KristianDD KristianDD force-pushed the kddimitrov/ios-11-log branch from be0856a to 6f87058 Compare October 16, 2017 07:46
@KristianDD KristianDD force-pushed the kddimitrov/ios-11-log branch from 6f87058 to a9a73a4 Compare October 16, 2017 07:58
@KristianDD KristianDD changed the title DO NOT MERGE Fix iOS11 Simulator logs Fix iOS11 Simulator logs Oct 16, 2017
@KristianDD KristianDD merged commit 124d236 into master Oct 16, 2017
@KristianDD KristianDD deleted the kddimitrov/ios-11-log branch October 16, 2017 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants