I couldn't find a way with intel to reopen streams when logrotation happens.
A common scenario is that a process writes to a file, linux logrotation utility moves the file and signals the application to recreate the primary one:
application/intel writes to file.log
external process moves file.log => file.log.1
external process signal application/intel to reopen the stream so that application/intel writes to file.log again
AFAICS intel would needs at least two things to provide this:
a handler capable of performing the reopening
a way to let the application signal intel to reopen the stream
Here's a way how did it for my application for now. I created a ReopenableFileHandler:
var FileHandler = require('intel').handlers.File;
/**
* Extends intels filehandler and provides #_reopen() to be manually called
* whenever an external event moves the logfiles
*/
export default class ReopenableFileHandler extends FileHandler {
_reopen() {
if (this._stream) {
this._stream.end();
delete this._stream;
}
this._stream = this._open();
}
}
In my application I provide a helper to look into intel which handlers expose _reopen call it when I receive an external signal (common is SIGUSR2 on linux):
function reopenLogfiles() {
for (let i = 0; i < intel._handlers.length; i++) {
if (typeof intel._handlers[i]._reopen === 'function') {
intel._handlers[i]._reopen();
}
}
}
I couldn't find a way with intel to reopen streams when logrotation happens.
A common scenario is that a process writes to a file, linux logrotation utility moves the file and signals the application to recreate the primary one:
file.log
file.log
=>file.log.1
file.log
againAFAICS intel would needs at least two things to provide this:
Here's a way how did it for my application for now. I created a ReopenableFileHandler:
In my application I provide a helper to look into intel which handlers expose
_reopen
call it when I receive an external signal (common is SIGUSR2 on linux):Maybe these snippets can serve as an inspiration.