Last active
May 11, 2019 01:19
-
-
Save suprememoocow/5133080 to your computer and use it in GitHub Desktop.
A function for reopening a winston File logging transport post logrotation on a HUP signal. To send a HUP to your node service, use the postrotate configuration option from logrotate. `postrotate kill -HUP ‘cat /var/run/mynodeservice.pid‘`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reopenTransportOnHupSignal(fileTransport) { | |
process.on('SIGHUP', function() { | |
var fullname = path.join(fileTransport.dirname, fileTransport._getFile(false)); | |
function reopen() { | |
if (fileTransport._stream) { | |
fileTransport._stream.end(); | |
fileTransport._stream.destroySoon(); | |
} | |
var stream = fs.createWriteStream(fullname, fileTransport.options); | |
stream.setMaxListeners(Infinity); | |
fileTransport._size = 0; | |
fileTransport._stream = stream; | |
fileTransport.once('flush', function () { | |
fileTransport.opening = false; | |
fileTransport.emit('open', fullname); | |
}); | |
fileTransport.flush(); | |
} | |
fs.stat(fullname, function (err) { | |
if (err && err.code == 'ENOENT') { | |
return reopen(); | |
} | |
}); | |
}); | |
} |
please, can you show who is fileTransport param?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would avoid using logrotate
copytruncate
if you are worried about logging log data. Per the logrotate docs: