Skip to content

Fixed: CLI crashes/stops responding after ~80 console.logs #2295

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 1 commit into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 44 additions & 24 deletions lib/services/ios-log-filter.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
let sourcemap = require("source-map");
import * as path from "path";
import fs = require("fs");

export class IOSLogFilter implements Mobile.IPlatformLogFilter {

private $projectData: IProjectData;
private partialLine: string = null;

constructor(
private $fs: IFileSystem,
private $loggingLevels: Mobile.ILoggingLevels) { }
constructor(private $fs: IFileSystem, private $loggingLevels: Mobile.ILoggingLevels) {
}

public filterData(data: string, logLevel: string, pid?: string): string {

if (pid && data && data.indexOf(`[${pid}]`) === -1) {
return null;
}

let skipLastLine = data[data.length-1] !== "\n";

if (data) {
if (data.indexOf("SecTaskCopyDebugDescription") !== -1 ||
data.indexOf("NativeScript loaded bundle") !== -1 ||
(data.indexOf("assertion failed:") !== -1 && data.indexOf("libxpc.dylib") !== -1)) {
return null;
}
// CONSOLE LOG messages comme in the following form:
// <date> <domain> <app>[pid] CONSOLE LOG file:///location:row:column: <actual message goes here>
// This code removes unnecessary information from log messages. The output looks like:
// CONSOLE LOG file:///location:row:column: <actual message goes here>
if (pid) {
let searchString = "["+pid+"]: ";
let pidIndex = data.indexOf(searchString);
if (pidIndex > 0) {
data = data.substring(pidIndex + searchString.length, data.length);
let lines = data.split("\n");
let result = "";
for (let i = 0; i<lines.length; i++) {
let line = lines[i];
if (i === 0 && this.partialLine) {
line = this.partialLine + line;
this.partialLine = null;
}
if (line.length < 1 ||
line.indexOf("SecTaskCopyDebugDescription") !== -1 ||
line.indexOf("NativeScript loaded bundle") !== -1 ||
(line.indexOf("assertion failed:") !== -1 && data.indexOf("libxpc.dylib") !== -1)) {
continue;
}
// CONSOLE LOG messages comme in the following form:
// <date> <domain> <app>[pid] CONSOLE LOG file:///location:row:column: <actual message goes here>
// This code removes unnecessary information from log messages. The output looks like:
// CONSOLE LOG file:///location:row:column: <actual message goes here>
if (pid) {
let searchString = "["+pid+"]: ";
let pidIndex = line.indexOf(searchString);
if (pidIndex > 0) {
line = line.substring(pidIndex + searchString.length, line.length);
this.getOriginalFileLocation(line);
result += this.getOriginalFileLocation(line) + "\n";
continue;
}
}
if (skipLastLine && i === lines.length-1) {
this.partialLine = line;
} else {
result += this.getOriginalFileLocation(line) + "\n";
}
}
data = this.getOriginalFileLocation(data);
return data.trim();
return result;
}

return data;
Expand All @@ -47,11 +67,11 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
if (parts.length >= 4) {
let file = parts[0];
if (this.ensureProjectData()) {
let sourceMapFile = path.join(this.$projectData.projectDir, file + ".map");
let row = parseInt(parts[1]);
let column = parseInt(parts[2]);
if (this.$fs.exists(sourceMapFile).wait()) {
let sourceMap = this.$fs.readText(sourceMapFile, "utf8").wait();
let sourceMapFile = path.join(this.$projectData.projectDir, file + ".map");
let row = parseInt(parts[1]);
let column = parseInt(parts[2]);
if (fs.existsSync(sourceMapFile)) {
let sourceMap = fs.readFileSync(sourceMapFile, "utf8");
let smc = new sourcemap.SourceMapConsumer(sourceMap);
let originalPosition = smc.originalPositionFor({line:row,column:column});
let sourceFile = smc.sources.length > 0 ? file.replace(smc.file, smc.sources[0]) : file;
Expand Down