const winston = require('winston');

module.exports = ({
  filename,
  level,
  transports: transports = [{ type: 'Console', options: { level: 'debug' } }],
}) => {
  if (filename) {
    transports.push({
      type: 'File',
      options: { filename, level: 'debug' },
    });
  }
  if (level) {
    for (const transport of transports) {
      transport.options = transport.options || {};
      transport.options.level = level;
    }
  }
  return (category, options) => {
    const logger = new winston.Logger(options);
    for (const transport of transports) {
      logger.add(
        winston.transports[transport.type],
        Object.assign({}, transport.options, { label: category })
      );
    }
    return logger;
  };
};

const winston = require('winston');

module.exports = ({
  level,
  transports: transports = [
    {
      type: 'Console',
      options: {
        timestamp: true,
        colorize: process.env.NODE_ENV !== 'production',
        prettyPrint: process.env.NODE_ENV !== 'production',
        json: process.env.NODE_ENV === 'production',
        stringify: obj => JSON.stringify(obj),
        silent: process.env.NODE_ENV === 'test',
        level: 'debug',
      },
    },
  ],
}) => {
  if (level) {
    for (const transport of transports) {
      transport.options = transport.options || {};
      transport.options.level = level;
    }
  }
  return (category, options) => {
    const logger = new winston.Logger(options);
    for (const transport of transports) {
      logger.add(
        winston.transports[transport.type],
        Object.assign({}, transport.options, { label: category })
      );
    }
    return logger;
  };
};

Replace default transport for logging, remove file logging
Replace default transport for logging, remove file logging
