Skip to content

Fixed tns device log throws exception #2174

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
Nov 1, 2016
Merged
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
44 changes: 27 additions & 17 deletions lib/services/ios-log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import * as path from "path";

export class IOSLogFilter implements Mobile.IPlatformLogFilter {

private $projectData: IProjectData;

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

public filterData(data: string, logLevel: string, pid?: string): string {
Expand All @@ -22,16 +23,16 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
}
// 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>
// 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);
data = this.getOriginalFileLocation(data);
}
}
data = this.getOriginalFileLocation(data);
return data.trim();
}

Expand All @@ -45,24 +46,33 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
let parts = data.substring(fileIndex + fileString.length).split(":");
if (parts.length >= 4) {
let file = parts[0];
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 smc = new sourcemap.SourceMapConsumer(sourceMap);
let originalPosition = smc.originalPositionFor({line:row,column:column});
data = data.substring(0, fileIndex + fileString.length)
+ file.replace(".js", ".ts") + ":"
+ originalPosition.line + ":"
+ originalPosition.column;
for (let i = 3; i<parts.length; i++) {
data += ":" + parts[i];
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 smc = new sourcemap.SourceMapConsumer(sourceMap);
let originalPosition = smc.originalPositionFor({line:row,column:column});
data = data.substring(0, fileIndex + fileString.length)
+ file.replace(".js", ".ts") + ":"
+ originalPosition.line + ":"
+ originalPosition.column;
for (let i = 3; i<parts.length; i++) {
data += ":" + parts[i];
}
}
}
}
}
return data;
}

private ensureProjectData(): boolean {
if (!this.$projectData) {
this.$projectData = $injector.resolve("projectData");
}
return !!this.$projectData;
}
}
$injector.register("iOSLogFilter", IOSLogFilter);