Merge pull request #125 from ascom-au/master
Rotating-file stream prevent process from exiting
This commit is contained in:
commit
7fb58aa5e4
4 changed files with 36 additions and 1 deletions
|
@ -8,7 +8,7 @@ Known issues:
|
||||||
|
|
||||||
## bunyan 0.23.1 (not yet released)
|
## bunyan 0.23.1 (not yet released)
|
||||||
|
|
||||||
(nothing yet)
|
- #97 Unref rotating-file timeout which was preventing processes from exiting
|
||||||
|
|
||||||
|
|
||||||
## bunyan 0.23.0
|
## bunyan 0.23.0
|
||||||
|
|
|
@ -1017,6 +1017,9 @@ RotatingFileStream.prototype._setupNextRot = function () {
|
||||||
this.timeout = setTimeout(
|
this.timeout = setTimeout(
|
||||||
function () { self.rotate(); },
|
function () { self.rotate(); },
|
||||||
this.rotAt - Date.now());
|
this.rotAt - Date.now());
|
||||||
|
if (typeof this.timeout.unref === 'function') {
|
||||||
|
this.timeout.unref();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RotatingFileStream.prototype._nextRotTime = function _nextRotTime(first) {
|
RotatingFileStream.prototype._nextRotTime = function _nextRotTime(first) {
|
||||||
|
|
11
test/process-exit.js
Normal file
11
test/process-exit.js
Normal file
|
@ -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
test/process-exit.test.js
Normal file
21
test/process-exit.test.js
Normal file
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue