Skip to content

Commit

Permalink
[refactor] Remove logging from forever.Monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Dec 9, 2011
1 parent 8a9af6b commit ab0f8e9
Showing 1 changed file with 1 addition and 59 deletions.
60 changes: 1 addition & 59 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ var Monitor = exports.Monitor = function (script, options) {
}

//
// Setup log files and logger for this instance.
// Setup logger for this instance.
//
this.logFile = options.logFile || path.join(forever.config.get('root'), this.uid + '.log');
this.outFile = options.outFile;
this.errFile = options.errFile;
this.logger = options.logger || new (winston.Logger)({
transports: [new winston.transports.Console({ silent: this.silent })]
});
Expand All @@ -107,16 +104,6 @@ var Monitor = exports.Monitor = function (script, options) {
this.options[0] = path.join(this.sourceDir, this.options[0]);
}

// If we should log stdout, open a file buffer
if (this.outFile) {
this.stdout = fs.createWriteStream(this.outFile, { flags: 'a+', encoding: 'utf8', mode: '0666' });
}

// If we should log stderr, open a file buffer
if (this.errFile) {
this.stderr = fs.createWriteStream(this.errFile, { flags: 'a+', encoding: 'utf8', mode: '0666' });
}

//
// Last if any hooks have been passed in attach
// this instance to them
Expand Down Expand Up @@ -167,37 +154,6 @@ Monitor.prototype.start = function (restart) {
self.emit(restart ? 'restart' : 'start', self, self.data);
});

// Hook all stream data and process it
function listenTo(stream) {
function ldata(data) {
if (!self.silent && !self[stream]) {
//
// If we haven't been silenced, and we don't have a file stream
// to output to write to the process stdout stream
//
process.stdout.write(data);
}
else if (self[stream]) {
//
// If we have been given an output file for the stream, write to it
//
self[stream].write(data);
}

self.emit(stream, data);
}

child[stream].on('data', ldata);

child.on('exit', function () {
child[stream].removeListener('data', ldata);
});
}

// Listen to stdout and stderr
listenTo('stdout');
listenTo('stderr');

child.on('exit', function (code) {
var spinning = Date.now() - self.ctime < self.minUptime;
self.warn('Forever detected script exited with code: ' + code);
Expand All @@ -206,20 +162,6 @@ Monitor.prototype.start = function (restart) {
self.running = false;
self.forceStop = false;

//
// If had to write to an stdout file, close it
//
if (self.stdout) {
self.stdout.end();
}

//
// If had to write to an stderr file, close it
//
if (self.stderr) {
self.stderr.end();
}

self.emit('exit', self, spinning);
}

Expand Down

0 comments on commit ab0f8e9

Please sign in to comment.