1
1
let sourcemap = require ( "source-map" ) ;
2
2
import * as path from "path" ;
3
+ import fs = require( "fs" ) ;
3
4
4
5
export class IOSLogFilter implements Mobile . IPlatformLogFilter {
5
6
6
7
private $projectData : IProjectData ;
8
+ private partialLine : string = null ;
7
9
8
- constructor (
9
- private $fs : IFileSystem ,
10
- private $loggingLevels : Mobile . ILoggingLevels ) { }
10
+ constructor ( private $fs : IFileSystem , private $loggingLevels : Mobile . ILoggingLevels ) {
11
+ }
11
12
12
13
public filterData ( data : string , logLevel : string , pid ?: string ) : string {
13
14
14
15
if ( pid && data && data . indexOf ( `[${ pid } ]` ) === - 1 ) {
15
16
return null ;
16
17
}
17
18
19
+ let skipLastLine = data [ data . length - 1 ] !== "\n" ;
20
+
18
21
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" ;
33
54
}
34
55
}
35
- data = this . getOriginalFileLocation ( data ) ;
36
- return data . trim ( ) ;
56
+ return result ;
37
57
}
38
58
39
59
return data ;
@@ -47,11 +67,11 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
47
67
if ( parts . length >= 4 ) {
48
68
let file = parts [ 0 ] ;
49
69
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" ) ;
55
75
let smc = new sourcemap . SourceMapConsumer ( sourceMap ) ;
56
76
let originalPosition = smc . originalPositionFor ( { line :row , column :column } ) ;
57
77
let sourceFile = smc . sources . length > 0 ? file . replace ( smc . file , smc . sources [ 0 ] ) : file ;
0 commit comments