2
2
"use strict" ;
3
3
4
4
import childProcess = require( "./child-process" ) ;
5
+ import * as child_process from "child_process" ;
5
6
import errors = require( "./errors" ) ;
6
7
7
8
import common = require( "./iphone-simulator-common" ) ;
@@ -119,7 +120,7 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
119
120
}
120
121
}
121
122
122
- public printDeviceLog ( deviceId : string , launchResult ?: string ) : any {
123
+ public printDeviceLog ( deviceId : string , launchResult ?: string ) : child_process . ChildProcess {
123
124
let pid = "" ;
124
125
let deviceLogChildProcess ;
125
126
@@ -130,46 +131,39 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
130
131
if ( ! this . isDeviceLogOperationStarted ) {
131
132
deviceLogChildProcess = this . getDeviceLogProcess ( deviceId ) ;
132
133
if ( deviceLogChildProcess . stdout ) {
133
- deviceLogChildProcess . stdout . on ( "data" , ( data : NodeBuffer ) => {
134
- let dataAsString = data . toString ( ) ;
135
- if ( pid ) {
136
- if ( dataAsString . indexOf ( `[${ pid } ]` ) > - 1 || dataAsString . indexOf ( ` ${ pid } ` ) > - 1 ) {
137
- process . stdout . write ( dataAsString ) ;
138
- }
139
- } else {
140
- process . stdout . write ( dataAsString ) ;
141
- }
142
- } ) ;
134
+ deviceLogChildProcess . stdout . on ( "data" , this . logDataHandler . bind ( this , pid ) ) ;
143
135
}
144
136
145
137
if ( deviceLogChildProcess . stderr ) {
146
- deviceLogChildProcess . stderr . on ( "data" , ( data : string ) => {
147
- let dataAsString = data . toString ( ) ;
148
- if ( pid ) {
149
- if ( dataAsString . indexOf ( `[${ pid } ]` ) > - 1 || dataAsString . indexOf ( ` ${ pid } ` ) > - 1 ) {
150
- process . stdout . write ( dataAsString ) ;
151
- }
152
- } else {
153
- process . stdout . write ( dataAsString ) ;
154
- }
155
- process . stdout . write ( data . toString ( ) ) ;
156
- } ) ;
138
+ deviceLogChildProcess . stderr . on ( "data" , this . logDataHandler . bind ( this , pid ) ) ;
157
139
}
158
140
}
159
141
160
142
return deviceLogChildProcess ;
161
143
}
162
144
163
- public getDeviceLogProcess ( deviceId : string ) : any {
164
- const device = this . getDeviceFromIdentifier ( deviceId ) || { } ;
165
- const deviceVersion = this . getDeviceFromIdentifier ( deviceId ) . runtimeVersion || "" ;
166
- const majorVersion = deviceVersion . split ( "." ) [ 0 ] ;
145
+ private logDataHandler ( pid : string , logData : NodeBuffer ) : void {
146
+ const dataAsString = logData . toString ( ) ;
167
147
148
+ if ( pid ) {
149
+ if ( dataAsString . indexOf ( `[${ pid } ]` ) > - 1 ) {
150
+ process . stdout . write ( dataAsString ) ;
151
+ }
152
+ } else {
153
+ process . stdout . write ( dataAsString ) ;
154
+ }
155
+ }
156
+
157
+ public getDeviceLogProcess ( deviceId : string , predicate ?: string ) : child_process . ChildProcess {
168
158
if ( ! this . isDeviceLogOperationStarted ) {
169
- if ( majorVersion && parseInt ( majorVersion ) >= 11 ) {
170
- this . deviceLogChildProcess = this . simctl . getLog ( deviceId ) ;
159
+ const device = this . getDeviceFromIdentifier ( deviceId ) ;
160
+ const deviceVersion = device ? device . runtimeVersion : "" ;
161
+ const majorVersion = deviceVersion . split ( "." ) [ 0 ] ;
162
+
163
+ if ( majorVersion && parseInt ( majorVersion ) >= 11 ) {
164
+ this . deviceLogChildProcess = this . simctl . getLog ( deviceId , predicate ) ;
171
165
} else {
172
- let logFilePath = path . join ( osenv . home ( ) , "Library" , "Logs" , "CoreSimulator" , deviceId , "system.log" ) ;
166
+ const logFilePath = path . join ( osenv . home ( ) , "Library" , "Logs" , "CoreSimulator" , deviceId , "system.log" ) ;
173
167
this . deviceLogChildProcess = require ( "child_process" ) . spawn ( "tail" , [ '-f' , '-n' , '1' , logFilePath ] ) ;
174
168
}
175
169
0 commit comments