3
3
var path = require ( 'path' ) ,
4
4
fs = require ( 'fs' ) ,
5
5
eyes = require ( 'eyes' ) ,
6
+ winston = require ( 'winston' ) ,
6
7
sys = require ( 'sys' ) ;
7
8
8
9
var accepts = [ 'start' , 'stop' , 'stopall' , 'list' , 'cleanlogs' , 'restart' ] , action ;
@@ -34,6 +35,7 @@ var help = [
34
35
" -d SOURCEDIR The source directory for which SCRIPT is relative to" ,
35
36
" -p PATH Base path for all forever related files (pid files, etc.)" ,
36
37
" -c COMMAND COMMAND to execute (defaults to node)" ,
38
+ " -v, --verbose Turns on the verbose messages from Forever" ,
37
39
" -s, --silent Run the child script silencing stdout and stderr" ,
38
40
" -h, --help You're staring at it" ,
39
41
"" ,
@@ -51,15 +53,17 @@ var help = [
51
53
] . join ( '\n' ) ;
52
54
53
55
var mappings = {
54
- 'm' : 'max' ,
55
- 'l' : 'logFile' ,
56
- 'p' : 'path' ,
57
- 'c' : 'command' ,
58
- 'd' : 'sourceDir' ,
59
- 's' : 'silent' ,
60
- 'silent' : 'silent' ,
61
- 'o' : 'outFile' ,
62
- 'e' : 'errFile'
56
+ 'c' : 'command' ,
57
+ 'e' : 'errFile' ,
58
+ 'd' : 'sourceDir' ,
59
+ 'l' : 'logFile' ,
60
+ 'm' : 'max' ,
61
+ 'o' : 'outFile' ,
62
+ 'p' : 'path' ,
63
+ 's' : 'silent' ,
64
+ 'silent' : 'silent' ,
65
+ 'v' : 'verbose' ,
66
+ 'verbose' : 'verbose'
63
67
} ;
64
68
65
69
function isSimpleAction ( ) {
@@ -101,6 +105,15 @@ if (typeof options['max'] === 'undefined') {
101
105
// restarting outside of the main directory
102
106
if ( ! options . sourceDir ) options . sourceDir = process . cwd ( ) ;
103
107
108
+ //
109
+ // Configure winston for forever based on the CLI options
110
+ //
111
+ winston . defaultTransports ( ) . console . timestamp = false ;
112
+ winston . defaultTransports ( ) . console . colorize = true ;
113
+ if ( options . verbose ) {
114
+ winston . defaultTransports ( ) . console . level = 'silly' ;
115
+ }
116
+
104
117
// Setup configurations for forever
105
118
var config = {
106
119
root : argv . p
@@ -116,7 +129,7 @@ function tryStart (callback) {
116
129
117
130
forever . stat ( fullLog , fullScript , function ( err ) {
118
131
if ( err ) {
119
- sys . puts ( 'Cannot start forever: ' + err . message ) ;
132
+ winston . error ( 'Cannot start forever: ' + err . message ) ;
120
133
process . exit ( 0 ) ;
121
134
}
122
135
@@ -129,28 +142,26 @@ function tryStart (callback) {
129
142
// the default root exposed by forever.
130
143
//
131
144
if ( config . root && config . root !== forever . root ) {
132
- sys . puts ( 'Loading forever with config: ' ) ;
133
- eyes . inspect ( config ) ;
145
+ winston . silly ( 'Loading forever with config: ' , config ) ;
134
146
135
147
forever . load ( config ) ;
136
- sys . puts ( 'Loaded forever successfully.' ) ;
148
+ winston . silly ( 'Loaded forever successfully.' ) ;
137
149
}
138
150
139
- sys . puts ( 'Tidying ' + forever . config . root ) ;
151
+ winston . silly ( 'Tidying ' + forever . config . root ) ;
140
152
var tidy = forever . cleanUp ( action === 'cleanlogs' ) ;
141
153
tidy . on ( 'cleanUp' , function ( ) {
142
- sys . puts ( forever . config . root + ' tidied.' ) ;
154
+ winston . silly ( forever . config . root + ' tidied.' ) ;
143
155
if ( file ) {
144
- sys . puts ( 'Working with file: ' + file ) ;
156
+ winston . info ( 'Forever processing arguments' , { arg : file } ) ;
145
157
}
146
158
147
159
if ( options ) {
148
- sys . puts ( 'Using forever options:' ) ;
149
- eyes . inspect ( options ) ;
160
+ winston . silly ( 'Forever using options' , options ) ;
150
161
}
151
162
152
163
if ( action ) {
153
- sys . puts ( 'Running action: ' + action . yellow ) ;
164
+ winston . info ( 'Running action: ' + action . yellow ) ;
154
165
switch ( action ) {
155
166
case 'start' :
156
167
tryStart ( function ( ) { forever . startDaemon ( file , options ) ; } ) ;
@@ -159,23 +170,23 @@ tidy.on('cleanUp', function () {
159
170
case 'stop' :
160
171
var runner = forever . stop ( file , true ) ;
161
172
runner . on ( 'stop' , function ( process ) {
162
- sys . puts ( 'Forever stopped process:' ) ;
173
+ winston . info ( 'Forever stopped process:' ) ;
163
174
sys . puts ( process ) ;
164
175
} ) ;
165
176
runner . on ( 'error' , function ( err ) {
166
- sys . puts ( 'Forever cannot find process with index: ' + file )
177
+ winston . error ( 'Forever cannot find process with index: ' + file )
167
178
} )
168
179
break ;
169
180
170
181
case 'stopall' :
171
182
var runner = forever . stopAll ( true ) ;
172
183
runner . on ( 'stopAll' , function ( processes ) {
173
184
if ( processes ) {
174
- sys . puts ( 'Forever stopped processes:' ) ;
185
+ winston . info ( 'Forever stopped processes:' ) ;
175
186
sys . puts ( processes ) ;
176
187
}
177
188
else {
178
- sys . puts ( 'No forever processes running' ) ;
189
+ winston . info ( 'No forever processes running' ) ;
179
190
}
180
191
} ) ;
181
192
break ;
@@ -184,18 +195,24 @@ tidy.on('cleanUp', function () {
184
195
var runner = forever . restart ( file , true ) ;
185
196
runner . on ( 'restart' , function ( processes ) {
186
197
if ( processes ) {
187
- sys . puts ( 'Forever restarted processes:' ) ;
198
+ winston . info ( 'Forever restarted processes:' ) ;
188
199
sys . puts ( processes ) ;
189
200
}
190
201
else {
191
- sys . puts ( 'No forever processes running' ) ;
202
+ winston . info ( 'No forever processes running' ) ;
192
203
}
193
204
} ) ;
194
205
break ;
195
206
196
207
case 'list' :
197
208
var processes = forever . list ( true ) ;
198
- sys . puts ( processes ? processes : 'No forever processes running' ) ;
209
+ if ( processes ) {
210
+ winston . info ( 'Forever processes running' ) ;
211
+ sys . puts ( processes ) ;
212
+ }
213
+ else {
214
+ winston . info ( 'No forever processes running' ) ;
215
+ }
199
216
break ;
200
217
}
201
218
}
0 commit comments