Skip to content

Fix iOS device log filter #2617

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
Mar 17, 2017
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
2 changes: 2 additions & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,5 @@ $injector.require("iOSLogFilter", "./services/ios-log-filter");
$injector.require("projectChangesService", "./services/project-changes-service");

$injector.require("emulatorPlatformService", "./services/emulator-platform-service");

$injector.require("staticConfig", "./config");
5 changes: 5 additions & 0 deletions lib/nativescript-cli-lib-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ $injector.requirePublic("companionAppsService", "./common/appbuilder/services/li
$injector.requirePublicClass("deviceEmitter", "./common/appbuilder/device-emitter");
$injector.requirePublicClass("deviceLogProvider", "./common/appbuilder/device-log-provider");
$injector.requirePublicClass("localBuildService", "./services/local-build-service");
$injector.require("iOSLogFilter", "./common/mobile/ios/ios-log-filter");

// We need this because some services check if (!$options.justLaunch) to start the device log after some operation.
// We don't want this behaviour when the CLI is required as library.
$injector.resolve("options").justLaunch = true;
34 changes: 23 additions & 11 deletions lib/services/ios-log-filter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
let sourcemap = require("source-map");
import * as path from "path";
import { cache } from "../common/decorators";

export class IOSLogFilter implements Mobile.IPlatformLogFilter {

private partialLine: string = null;

constructor(private $fs: IFileSystem) {
}

public filterData(data: string, logLevel: string, projectDir: string, pid?: string): string {
constructor(private $fs: IFileSystem,
private $projectData: IProjectData) { }

public filterData(data: string, logLevel: string, pid?: string): string {
if (pid && data && data.indexOf(`[${pid}]`) === -1) {
return null;
}
Expand Down Expand Up @@ -40,15 +40,15 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
let pidIndex = line.indexOf(searchString);
if (pidIndex > 0) {
line = line.substring(pidIndex + searchString.length, line.length);
this.getOriginalFileLocation(line, projectDir);
result += this.getOriginalFileLocation(line, projectDir) + "\n";
this.getOriginalFileLocation(line);
result += this.getOriginalFileLocation(line) + "\n";
continue;
}
}
if (skipLastLine && i === lines.length - 1) {
this.partialLine = line;
} else {
result += this.getOriginalFileLocation(line, projectDir) + "\n";
result += this.getOriginalFileLocation(line) + "\n";
}
}
return result;
Expand All @@ -57,11 +57,12 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
return data;
}

private getOriginalFileLocation(data: string, projectDir: string): string {
let fileString = "file:///";
let fileIndex = data.indexOf(fileString);
private getOriginalFileLocation(data: string): string {
const fileString = "file:///";
const fileIndex = data.indexOf(fileString);
const projectDir = this.getProjectDir();

if (fileIndex >= 0) {
if (fileIndex >= 0 && projectDir) {
let parts = data.substring(fileIndex + fileString.length).split(":");
if (parts.length >= 4) {
let file = parts[0];
Expand All @@ -87,5 +88,16 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {

return data;
}

@cache()
private getProjectDir(): string {
try {
this.$projectData.initializeProjectData();
return this.$projectData.projectDir;
} catch (err) {
return null;
}
}
}

$injector.register("iOSLogFilter", IOSLogFilter);