1
1
import { ChildProcess } from "child_process" ;
2
2
3
3
export class IOSSimulatorLogProvider implements Mobile . IiOSSimulatorLogProvider {
4
- private isStarted : boolean ;
4
+ private simulatorsLoggingEnabled : IDictionary < boolean > = { } ;
5
5
6
6
constructor ( private $iOSSimResolver : Mobile . IiOSSimResolver ,
7
7
private $deviceLogProvider : Mobile . IDeviceLogProvider ,
8
8
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
9
+ private $logger : ILogger ,
9
10
private $processService : IProcessService ) { }
10
11
11
12
public startLogProcess ( deviceIdentifier : string ) : void {
12
- if ( ! this . isStarted ) {
13
+ if ( ! this . simulatorsLoggingEnabled [ deviceIdentifier ] ) {
13
14
const deviceLogChildProcess : ChildProcess = this . $iOSSimResolver . iOSSim . getDeviceLogProcess ( deviceIdentifier , 'senderImagePath contains "NativeScript"' ) ;
14
15
15
16
const action = ( data : NodeBuffer | string ) => {
16
17
this . $deviceLogProvider . logData ( data . toString ( ) , this . $devicePlatformsConstants . iOS , deviceIdentifier ) ;
17
18
} ;
18
19
20
+ if ( deviceLogChildProcess ) {
21
+ deviceLogChildProcess . once ( "close" , ( ) => {
22
+ this . simulatorsLoggingEnabled [ deviceIdentifier ] = false ;
23
+ } ) ;
24
+
25
+ deviceLogChildProcess . once ( "error" , ( err ) => {
26
+ this . $logger . trace ( `Error is thrown for device with identifier ${ deviceIdentifier } . More info: ${ err . message } .` ) ;
27
+ this . simulatorsLoggingEnabled [ deviceIdentifier ] = false ;
28
+ } ) ;
29
+ }
30
+
19
31
if ( deviceLogChildProcess . stdout ) {
20
32
deviceLogChildProcess . stdout . on ( "data" , action ) ;
21
33
}
@@ -26,7 +38,7 @@ export class IOSSimulatorLogProvider implements Mobile.IiOSSimulatorLogProvider
26
38
27
39
this . $processService . attachToProcessExitSignals ( this , deviceLogChildProcess . kill ) ;
28
40
29
- this . isStarted = true ;
41
+ this . simulatorsLoggingEnabled [ deviceIdentifier ] = true ;
30
42
}
31
43
}
32
44
}
0 commit comments