Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/logger / test / support / InMemoryTransport.js
Size: Mime:
/**
 * This file holds the implementation details of adding the test transport to the winston logger,
 * so that the log is readable in the test environment, and we don't pollute the local folder with files.
 */

const Transport = require('winston-transport');

/**
 * This winston transport pushes the logs into an array, so that they are readable in tests.
 */
class InMemoryTransport extends Transport {
  constructor(options = {}) {
    super(options);
    this._log = [];
  }

  log(info, callback) {
    setImmediate(() => this.emit('logged', info));

    this._log.push(info);

    if (callback) {
      callback();
    }
  }

  getLog() {
    return this._log;
  }

  clearLog() {
    this._log = [];
  }
}

module.exports = InMemoryTransport;