title: How to archive log files after they reach certain size limit in Node JS using winston?
body: <p>I am new to Node JS. I was looking for a logging library for Node and I found Winston. Now, I want to archive the log files once they reach certain size with the timestamp included in name.</p>
  
  <p><strong>For ex:</strong></p>
  
  <p>Current log file: logs/devlog.log(10 MB)</p>
  
  <p>since it reached 10 MB, I want to archive it</p>
  
  <p>archived log file: Archive/devlog-03.02.2016.log</p>
  
  <p>please help me do that in winston or any other solution. Thanks in advance</p>
  
  <p>My code for app.js(Node server):</p>
  
  <pre><code>    console.log('Hello world');
  var winston = require('winston');
  var date1 = new Date();
  winston.emitErrs = true;
  var date = new Date();
  var loggerName = "server.app.js";
  var winston = require('winston'),
  path = require('path'),
  transports = [];
  
  transports.push(new winston.transports.DailyRotateFile({
      name: 'file',
      datePattern: '.yyyy-MM-ddTHH-mm',
      filename: path.join(__dirname, "logs", "log_file.log"),
      maxFiles: 5,
      maxsize: 100000000
  }));
  
  var logger = new winston.Logger({ transports: transports });
  //winston.loggers.add('ServerLogger', {
  //    transports: [
  //        new (winston.transports.File)({
  //            name: 'Devlogger', //Name of the transport
  //            filename: 'logs/devlogNormalF.log', // log file name
  //            json: false,
  //            maxsize: 1048576, //1MB
  //            maxFiles: 10, // 10 Files max
  //            timestamp: function () {
  //                return new Date().toISOString();//.substring(0,23);
  //            }
  //        }
  //        ), new archiveFile(options)
  //    ]
  //});
  //var logger = winston.loggers.get('ServerLogger');
  logger.info ('Logger Name: '+loggerName+' App starting...');
  logger.info('Logger Name: ' + loggerName + 'Hello world');
  logger.info('Logger Name: ' + loggerName + ' Accessing test/user');
  logger.error('Logger Name: ' + loggerName + ' Cannot access test/user/user.png');
  var express = require('express');
  var app = express();
  app.get('/', function (req, res) {
      res.send('Hello World!');
      var date2 = new Date();
      var diff = date2 - date1;
      logger.info('Start '+ date1+' Stop '+date2)
      logger.info('Logger Name: ' + loggerName + ' Response time of Node is ' + diff+' ms');
  });
  
  app.listen(3000, function () {
      logger.warn('Logger Name: ' + loggerName + ' Example app listening on port 3000!');
      logger.info('Logger Name: ' + loggerName + ' App ending...');
  });
  </code></pre>