title: Winston logger setting the timestamp of the log to 12/31/1969 instead of current time
body: <p>I'm setting up logging in an app with winston and occassionally when I run tests a separate file is created with the date 12/31/1969. Is there something explicit I need to put in the creation of the transport so that it knows what the current date is?</p>
  
  <p>What's very interesting is this seems to be a system wide anomaly as the <code>_log</code> method, which doesn't use the <code>new Date()</code> syntax, but the moment.js library also results in a 12-31-1969 inside the log file:
  <a href="https://i.stack.imgur.com/Q93m0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q93m0.png" alt="enter image description here"></a></p>
  
  <p>My logger:</p>
  
  <pre><code>class Logger{
    constructor(configs){
      if (!configs) configs = {};
      this.logDirectory = configs.directory ? path.join(__dirname, configs.directory) : path.join(__dirname, '../logs') ;
      this.initialize();
      this.date = moment().format("YYYY-MM-DD HH:mm:ss");
    }
  
    initialize() {
      this._createTransportObj();
      this._createLoggerObj();
    }
  
  
    _createTransportObj() {
      const DailyRotateFile = winston.transports.DailyRotateFile;
      this._transport = new DailyRotateFile({
        filename: path.join(this.logDirectory, '/log-%DATE%.log'),
        datePattern: 'YYYY-MM-DD',
        level: 'info'
      });
    }
  
    _createLoggerObj() {
      this._logger = winston.createLogger({
        level: 'info',
        format: winston.format.json(),
        transports: [this._transport],
        exitOnError: true
      });
  
      if (nodeEnv !== 'production') {
        this._logger.add(new winston.transports.Console({
          format: winston.format.simple()
        }));
      }
    }
  
    _log(type, msg, options) {
      const logMsg = {};
  
      const timestamp = moment().format("YYYY-MM-DD HH:mm:ss");
  
      logMsg.level = type || 'info';
      logMsg.time = timestamp;
      logMsg.msg = msg || '';
      logMsg.desc = options.description || '';
  
      // get the user that made the request if available
      if (options.user) logMsg.user = options.user;
  
      // get the url endpoint that was hit if available
      if (options.url) logMsg.url = options.url;
  
      // if an error is sent through, get the stack
      // and remove it from msg for readability
      if (msg.stack) {
        logMsg.stack = msg.stack;
        msg = msg.message ? msg.message : msg;
      }
  
      // get the ip address of the caller if available
      if (options.ip) logMsg.ip = options.ip;
  
      // get the body of the request if available
      if (options.body) logMsg.body = options.body;
  
      // get the query string of the request if available
      if (options.query) logMsg.query = options.query;
  
      // get the params string of the request if available
      if (options.params) logMsg.params = options.params;
  
      const jsonString = JSON.stringify(logMsg);
      this._logger.log(type, logMsg);
    }
  
    info(msg, options) {
      return this._log('info', msg, options);
    }
  
    error(msg, options) {
      return this._log('error', msg, options);
    }
  
    warn(msg, options) {
      return this._log('warn', msg, options);
    }
  
    verbose(msg, options) {
      return this._log('verbose', msg, options);
    }
  
    debug(msg, options) {
      return this._log('debug', msg, options);
    }
  
    silly(msg, options) {
      return this._log('silly', msg, options);
    }
  }
  
  module.exports = { Logger };
  </code></pre>
  
  <p>I'm currently only testing it in a promise handler that my routes flow through:</p>
  
  <pre><code>const asyncHandler = fn =&gt; (req, res, next) =&gt; {
    const logger = new Logger();
      Promise.resolve(fn(req, res, next))
          .then(result =&gt; {
            if (req.body.password) delete req.body.password;
            logger.info(result,
                { user: req.user.username,
                  url: req.originalUrl,
                  body: req.body,
                  description: '200:OK Response sent back successfully'
                });
            return res.status(200).json({ result })
          })
          .catch(e =&gt; {
              console.log(e);
              return res.status(400).json({ error: e.message })
          });
  };
  
  module.exports = asyncHandler;
  </code></pre>
  
  <p>UPDATE*
  ok, so it seems to not be the logger itself. I ran a batch of tests and noticed it's always the same route that triggers the date change. What's weird is I can't seem to figure out what's happening.</p>
  
  <p>The route is:
  <a href="https://i.stack.imgur.com/NjLri.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NjLri.png" alt="enter image description here"></a></p>
  
  <p>and the <code>app.use()</code> statement is as follows:
  <a href="https://i.stack.imgur.com/U306B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U306B.png" alt="enter image description here"></a></p>
  
  <p>finally the admin_access middleware is simple enought:
  <a href="https://i.stack.imgur.com/UqcXO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UqcXO.png" alt="enter image description here"></a></p>
  
  <p>I've figured out if I break the endpoint in the <code>app.js</code> file before it hits <code>admin_access</code> the date is correct. However if I break in <code>admin_access</code> the date is 12-31-1969. So what could be happening between the two? Is there something I could be setting unintentionally on this route?</p>