11let sourcemap = require ( "source-map" ) ;
22import * as path from "path" ;
3+ import fs = require( "fs" ) ;
34
45export class IOSLogFilter implements Mobile . IPlatformLogFilter {
56
67 private $projectData : IProjectData ;
8+ private partialLine : string = null ;
79
8- constructor (
9- private $fs : IFileSystem ,
10- private $loggingLevels : Mobile . ILoggingLevels ) { }
10+ constructor ( private $fs : IFileSystem , private $loggingLevels : Mobile . ILoggingLevels ) {
11+ }
1112
1213 public filterData ( data : string , logLevel : string , pid ?: string ) : string {
1314
1415 if ( pid && data && data . indexOf ( `[${ pid } ]` ) === - 1 ) {
1516 return null ;
1617 }
1718
19+ let skipLastLine = data [ data . length - 1 ] !== "\n" ;
20+
1821 if ( data ) {
19- if ( data . indexOf ( "SecTaskCopyDebugDescription" ) !== - 1 ||
20- data . indexOf ( "NativeScript loaded bundle" ) !== - 1 ||
21- ( data . indexOf ( "assertion failed:" ) !== - 1 && data . indexOf ( "libxpc.dylib" ) !== - 1 ) ) {
22- return null ;
23- }
24- // CONSOLE LOG messages comme in the following form:
25- // <date> <domain> <app>[pid] CONSOLE LOG file:///location:row:column: <actual message goes here>
26- // This code removes unnecessary information from log messages. The output looks like:
27- // CONSOLE LOG file:///location:row:column: <actual message goes here>
28- if ( pid ) {
29- let searchString = "[" + pid + "]: " ;
30- let pidIndex = data . indexOf ( searchString ) ;
31- if ( pidIndex > 0 ) {
32- data = data . substring ( pidIndex + searchString . length , data . length ) ;
22+ let lines = data . split ( "\n" ) ;
23+ let result = "" ;
24+ for ( let i = 0 ; i < lines . length ; i ++ ) {
25+ let line = lines [ i ] ;
26+ if ( i === 0 && this . partialLine ) {
27+ line = this . partialLine + line ;
28+ this . partialLine = null ;
29+ }
30+ if ( line . length < 1 ||
31+ line . indexOf ( "SecTaskCopyDebugDescription" ) !== - 1 ||
32+ line . indexOf ( "NativeScript loaded bundle" ) !== - 1 ||
33+ ( line . indexOf ( "assertion failed:" ) !== - 1 && data . indexOf ( "libxpc.dylib" ) !== - 1 ) ) {
34+ continue ;
35+ }
36+ // CONSOLE LOG messages comme in the following form:
37+ // <date> <domain> <app>[pid] CONSOLE LOG file:///location:row:column: <actual message goes here>
38+ // This code removes unnecessary information from log messages. The output looks like:
39+ // CONSOLE LOG file:///location:row:column: <actual message goes here>
40+ if ( pid ) {
41+ let searchString = "[" + pid + "]: " ;
42+ let pidIndex = line . indexOf ( searchString ) ;
43+ if ( pidIndex > 0 ) {
44+ line = line . substring ( pidIndex + searchString . length , line . length ) ;
45+ this . getOriginalFileLocation ( line ) ;
46+ result += this . getOriginalFileLocation ( line ) + "\n" ;
47+ continue ;
48+ }
49+ }
50+ if ( skipLastLine && i === lines . length - 1 ) {
51+ this . partialLine = line ;
52+ } else {
53+ result += this . getOriginalFileLocation ( line ) + "\n" ;
3354 }
3455 }
35- data = this . getOriginalFileLocation ( data ) ;
36- return data . trim ( ) ;
56+ return result ;
3757 }
3858
3959 return data ;
@@ -47,11 +67,11 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
4767 if ( parts . length >= 4 ) {
4868 let file = parts [ 0 ] ;
4969 if ( this . ensureProjectData ( ) ) {
50- let sourceMapFile = path . join ( this . $projectData . projectDir , file + ".map" ) ;
51- let row = parseInt ( parts [ 1 ] ) ;
52- let column = parseInt ( parts [ 2 ] ) ;
53- if ( this . $ fs. exists ( sourceMapFile ) . wait ( ) ) {
54- let sourceMap = this . $ fs. readText ( sourceMapFile , "utf8" ) . wait ( ) ;
70+ let sourceMapFile = path . join ( this . $projectData . projectDir , file + ".map" ) ;
71+ let row = parseInt ( parts [ 1 ] ) ;
72+ let column = parseInt ( parts [ 2 ] ) ;
73+ if ( fs . existsSync ( sourceMapFile ) ) {
74+ let sourceMap = fs . readFileSync ( sourceMapFile , "utf8" ) ;
5575 let smc = new sourcemap . SourceMapConsumer ( sourceMap ) ;
5676 let originalPosition = smc . originalPositionFor ( { line :row , column :column } ) ;
5777 let sourceFile = smc . sources . length > 0 ? file . replace ( smc . file , smc . sources [ 0 ] ) : file ;
0 commit comments