Skip to content

Commit

Permalink
fix: ios log filtering (#5679)
Browse files Browse the repository at this point in the history
* fix: ios log filtering

* fix: log filtering on device

* chore: cleanup comments
  • Loading branch information
rigor789 committed Jul 22, 2022
1 parent 98124e7 commit 8446000
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/services/ios-log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { injector } from "../common/yok";
export class IOSLogFilter implements Mobile.IPlatformLogFilter {
// Used to recognize output related to the current project
// This looks for artifacts like: AppName[22432] or AppName(SomeTextHere)[23123]
private appOutputRegex: RegExp = /([^\s\(\)]+)(?:\([^\s]+\))?\[[0-9]+\]/;
private appOutputRegex: RegExp = /([^\s\(\)]+)(?:\(([^\s]+)\))?\[[0-9]+\]/;

// Used to trim the passed messages to a simpler output
// Example:
Expand All @@ -13,6 +13,14 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
`^.*(?:<Notice>:|<Error>:|<Warning>:|\\(NativeScript\\)|${this.appOutputRegex.source}:){1}`
);

// Used to post filter messages that slip through but are not coming from NativeScript itself.
// Looks for text in parenthesis at the beginning
// Example:
// (RunningBoardServices) [com.apple.runningboard:connection] Identity resolved as application<...>
// ^(~~capture group~~~)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// we then use this to filter out non-NativeScript lines
protected postFilterRegex: RegExp = /^\((.+)\) \[com\.apple.+\]/;

private filterActive: boolean = true;

private partialLine: string = null;
Expand Down Expand Up @@ -59,6 +67,10 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
// of this filter may be used accross multiple projects.
const projectName = loggingOptions && loggingOptions.projectName;
this.filterActive = matchResult[1] !== projectName;

if (matchResult?.[2]) {
this.filterActive ||= matchResult[2] !== "NativeScript";
}
}

if (this.filterActive) {
Expand All @@ -71,6 +83,13 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
}

currentLine = currentLine.trim();

// post filtering: (<anything>) check if <anything> is not "NativeScript"
const postFilterMatch = this.postFilterRegex.exec(currentLine);
if (postFilterMatch && postFilterMatch?.[1] !== "NativeScript") {
continue;
}

output += currentLine + "\n";
}

Expand Down

0 comments on commit 8446000

Please sign in to comment.