Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotating-file stream prevent process from exiting #125

Merged
merged 4 commits into from
Jun 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Known issues:

## bunyan 0.22.2 (not yet released)

(nothing yet)
- #97 Unref rotating-file timeout which was preventing processes from exiting


## bunyan 0.22.1
Expand Down
3 changes: 3 additions & 0 deletions lib/bunyan.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,9 @@ RotatingFileStream.prototype._setupNextRot = function () {
this.timeout = setTimeout(
function () { self.rotate(); },
this.rotAt - Date.now());
if (typeof this.timeout.unref === 'function') {
this.timeout.unref();
}
}

RotatingFileStream.prototype._nextRotTime = function _nextRotTime(first) {
Expand Down
11 changes: 11 additions & 0 deletions test/process-exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var bunyan = require('../lib/bunyan');
var log = bunyan.createLogger({
name: 'default',
streams: [{
type: 'rotating-file',
path: __dirname + '/log.test.rot.log',
period: '1d',
count: 7
}]
});
console.log('done');
21 changes: 21 additions & 0 deletions test/process-exit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
/*
* Test that bunyan process will terminate
*/

var exec = require('child_process').exec;

// node-tap API
if (require.cache[__dirname + '/tap4nodeunit.js'])
delete require.cache[__dirname + '/tap4nodeunit.js'];
var tap4nodeunit = require('./tap4nodeunit.js');
var test = tap4nodeunit.test;

test('log with rotating file stream will terminate gracefully', function (t) {
exec('node ' +__dirname + '/process-exit.js', {timeout: 1000}, function(err, stdout, stderr) {
t.ifError(err);
t.equal(stdout, 'done\n');
t.equal(stderr, '');
t.end();
});
});