@@ -7,29 +7,44 @@ exports.attach = function (options) {
7
7
options = options || { } ;
8
8
var monitor = this ;
9
9
10
- monitor . on ( 'start' , function startLogs ( child , childData ) {
10
+
11
+ if ( options . outFile ) {
12
+ monitor . stdout = options . stdout || fs . createWriteStream ( options . outFile , {
13
+ flags : monitor . append ? 'a+' : 'w+' ,
14
+ encoding : 'utf8' ,
15
+ mode : 0644
16
+ } ) ;
17
+ }
18
+
19
+ if ( options . errFile ) {
20
+ monitor . stderr = options . stderr || fs . createWriteStream ( options . errFile , {
21
+ flags : monitor . append ? 'a+' : 'w+' ,
22
+ encoding : 'utf8' ,
23
+ mode : 0644
24
+ } ) ;
25
+ }
26
+
27
+ monitor . on ( 'start' , startLogs ) ;
28
+
29
+ monitor . on ( 'restart' , startLogs ) ;
30
+
31
+ monitor . on ( 'exit' , function ( ) {
32
+ monitor . stdout . end ( ) ;
33
+ monitor . stderr . end ( ) ;
34
+ } ) ;
35
+
36
+ function startLogs ( child , childData ) {
11
37
if ( monitor . child && ! monitor . silent ) {
12
- monitor . child . stdout . pipe ( process . stdout ) ;
13
- monitor . child . stderr . pipe ( process . stderr ) ;
14
- if ( monitor . outFile ) {
15
- monitor . stdout = fs . createWriteStream ( monitor . outFile , {
16
- flags : monitor . append ? 'a+' : 'w+' ,
17
- encoding : 'utf8' ,
18
- mode : 0644
19
- } ) ;
20
- monitor . child . stdout . pipe ( monitor . stdout ) ;
38
+ monitor . child . stdout . pipe ( process . stdout , { end : false } ) ;
39
+ monitor . child . stderr . pipe ( process . stderr , { end : false } ) ;
40
+ if ( monitor . stdout ) {
41
+ monitor . child . stdout . pipe ( monitor . stdout , { end : false } ) ;
21
42
}
22
- if ( monitor . errFile ) {
23
- monitor . stderr = fs . createWriteStream ( monitor . errFile , {
24
- flags : monitor . append ? 'a+' : 'w+' ,
25
- encoding : 'utf8' ,
26
- mode : 0644
27
- } ) ;
28
- monitor . child . stderr . pipe ( monitor . stderr ) ;
43
+ if ( monitor . stderr ) {
44
+ monitor . child . stderr . pipe ( monitor . stderr , { end : false } ) ;
29
45
}
30
46
}
31
- } ) ;
32
-
47
+ }
33
48
} ;
34
49
35
50
0 commit comments