Closed Rafi993 closed 8 years ago
The rotating file steam object emits an event every time a new file is created. The event info contains an object with information about the new file, including it's path, the stream and the filestat information.
This isn't part of the official api tho, and it might change between releases without a major version change. In particular, do not use that stream object you're given, it is definitely going away.
This is the event information:
base.emit('newfile', {
stream: stream,
logpath: streamPath,
stats: stats
});
so you can subscribe to the event something like this:
var rfs = RotatingFileStream(_.extend({}, { path: 'foo.log', map: fixpid }, options.stream));
var log = bunyan.createLogger({
name: 'foo',
streams: [{
type: 'raw',
stream: rfs
}]
});
rfs.on('error', function (err) {
console.log('err', err);
throw err;
});
rfs.on('newfile', function (fileinfo) {
// do not use fileinfo.stream
console.log('new file', fileinfo);
});
I hope this
actually I take that back, newfile event is part of the public api, but the stream object is still going to go away.
Thank you
How to I call a function automatically when a new file is created for logging i.e if the existing log file reaches limit and new one is created