Flush batch logger to not lose info
This commit is contained in:
parent
12e35b02e8
commit
f2b5921ade
25
app.js
25
app.js
@ -124,20 +124,19 @@ process.on('SIGHUP', function() {
|
||||
});
|
||||
|
||||
process.on('SIGTERM', function () {
|
||||
global.logger.debug('Signal TERM Received');
|
||||
listener.close();
|
||||
global.logger.debug('Http server closed');
|
||||
listener.close(function () {
|
||||
server.batch.stop(function () {
|
||||
server.batch.drain(function (err) {
|
||||
if (err) {
|
||||
global.logger.error(err);
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
server.batch.stop();
|
||||
global.logger.debug('Batch queries stopped');
|
||||
server.batch.drain(function (err) {
|
||||
if (err) {
|
||||
global.logger.error(err);
|
||||
return process.exit(1);
|
||||
}
|
||||
global.logger.debug('Batch queries drained');
|
||||
global.logger.info('Exit gracefully');
|
||||
process.exit(0);
|
||||
global.logger.info('Exit gracefully');
|
||||
server.batch.logger.end();
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,6 +50,21 @@ class Logger {
|
||||
reopenFileStreams () {
|
||||
this.logger.reopenFileStreams();
|
||||
}
|
||||
|
||||
// Ensures that the writable stream is flushed.
|
||||
// Use this function before exiting the process to not lose log entries
|
||||
//
|
||||
// See: https://github.com/trentm/node-bunyan/issues/37
|
||||
// See: https://github.com/trentm/node-bunyan/issues/73
|
||||
end () {
|
||||
// process.stdout cannot be closed
|
||||
if (!this.path) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.streams[0].stream.on('finish', resolve);
|
||||
this.logger.streams[0].stream.end(); // close stream, flush buffer to disk
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logger;
|
||||
|
Loading…
Reference in New Issue
Block a user