0

I am working on a very old Nodejs application which creates a new child process using forever-monitor. The logs of this child process are taken care by forever-monitor only. This is how the configuration looks like:

var child = new (forever.Monitor)(__dirname + '/../lib/childprocess.js', {
   max: 3,
   silent: true,
   options: [program.port],
   'errFile': __dirname + '/../childprocess_error.log',
   'outFile': __dirname + '/../childprocess_output.log'
}
);

Everything is working fine in this setup. The new requirement is to rotate these logs every 12 hours. That is every 12 hours a new file will be created which will have all the content of this file childprocess_output.log and should be stored in some other directory. The new log file will obviously have the timestamp appended at the end of the name (eg: childprocess_output_1239484034.log).

And the original file childprocess_output.log should be reset, that is all its content should be deleted and it should start logging from fresh.

I am trying to understand which npm library should I used for this purpose. I googled a bit and found a few of the npm libraries which matches my requirement, but the number of downloads for these libraries was really small, so I doubt the reliability of those libraries.

Which library NodeJs developers use for log rotation?

Also, my last resort would be to use the Linux tool Logrotate if I couldn't find any appropriate library in Node. I am avoiding using Logroate because I want my application to handle the scenario and not depend on the instance configuration.

James Z
  • 12,209
  • 10
  • 24
  • 44
Rito
  • 3,092
  • 2
  • 27
  • 40

1 Answers1

0

you can use : fs (the file system library) handled with methods like statSync and renameSync coupled with try-catches block-codes.

marcdahan
  • 2,654
  • 25
  • 25