Skip to content

Commit

Permalink
[fix] Alter logging paths to reduce memory leakage and prevent stdio …
Browse files Browse the repository at this point in the history
…issues.
  • Loading branch information
AvianFlu committed Feb 28, 2012
1 parent 5c8fcc5 commit 8186994
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 6 additions & 0 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ forever.stat = function (logFile, script, callback) {
// Starts a script with forever
//
forever.start = function (script, options) {
if (!options.uid) {
options.uid = options.uid || utile.randomString(4).replace(/^\-/, '_');
}
if (!options.logFile) {
options.logFile = forever.logFilePath(options.uid + '.log');
}
return new forever.Monitor(script, options).start();
};

Expand Down
16 changes: 6 additions & 10 deletions lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var Monitor = exports.Monitor = function (script, options) {
// can be attached through `monitor.use(plugin, options)`.
//
function bootstrap(monitor) {
forever.plugins.logger.attach.call(monitor, options);

if (options.watch) {
forever.plugins.watch.attach.call(monitor, options);
Expand All @@ -53,22 +52,14 @@ var Monitor = exports.Monitor = function (script, options) {
this.childExists = false;
this.checkFile = options.checkFile !== false;
this.times = 0;
this.daemon = options.daemon || false;

//
// Setup log files and 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 })]
});

//
// Extend from the winston logger.
//
this.logger.extend(this);
this.log = fs.createWriteStream(this.logFile, { flags: 'a+', encoding: 'utf8', mode: '0666' });

//
// Setup restart timing. These options control how quickly forever restarts
Expand Down Expand Up @@ -153,6 +144,11 @@ Monitor.prototype.start = function (restart) {
return this;
}

if (!this.silent) {
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
}

this.ctime = Date.now();
this.child = child;
this.running = true;
Expand Down

0 comments on commit 8186994

Please sign in to comment.