<commit_before>const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const WFirehose = require('winston-firehose');

// Logging levels map to npm logging levels
// enable or disable an exported logger method by commenting out/in one of these levels
const LOGGING_LEVELS = ['error', 'warn', 'info', 'verbose', 'debug', 'silly'];

/*
example output
{
  "created": "2017-10-31T20:24:59.402Z",
  "level": "info",
  "label": "to-fix-backend",
  "secondaryLabel": "index",
  "event": "app_start",
  "message": "listing on port: 8889"
}
*/
const logDriverFormat = combine(
  label({ label: 'to-fix-backend' }),
  timestamp(),
  printf(log => {
    const { timestamp, label, secondaryLabel, level, message, event } = log;
    return JSON.stringify({
      created: timestamp,
      level,
      label,
      secondaryLabel,
      event,
      message
    });
  })
);

const exportDriver = createLogger({
  format: logDriverFormat,
  transports: [new WFirehose()]
});

const internalLogger = createLogger({
  format: logDriverFormat,
  transports: [new transports.Console()]
});

module.exports = function(secondaryLabel) {
  const defaultOpts = {
    exportLog: false,
    event: ''
  };
  return LOGGING_LEVELS.reduce((exportedMethods, level) => {
    exportedMethods[level] = (message, { exportLog, event } = defaultOpts) => {
      if (exportLog) {
        return exportDriver.log({
          level,
          secondaryLabel,
          exportLog,
          event,
          message
        });
      } else {
        return internalLogger.log({
          level,
          secondaryLabel,
          exportLog,
          event,
          message
        });
      }
    };
    return exportedMethods;
  }, {});
};<commit_msg>multiline stringify<commit_after>const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const WFirehose = require('winston-firehose');

// Logging levels map to npm logging levels
// enable or disable an exported logger method by commenting out/in one of these levels
const LOGGING_LEVELS = ['error', 'warn', 'info', 'verbose', 'debug', 'silly'];

/*
example output
{
  "created": "2017-10-31T20:24:59.402Z",
  "level": "info",
  "label": "to-fix-backend",
  "secondaryLabel": "index",
  "event": "app_start",
  "message": "listing on port: 8889"
}
*/
const logDriverFormat = combine(
  label({ label: 'to-fix-backend' }),
  timestamp(),
  printf(log => {
    const { timestamp, label, secondaryLabel, level, message, event } = log;
    return multilineStringify({
      created: timestamp,
      level,
      label,
      secondaryLabel,
      event,
      message
    });
  })
);

const exportDriver = createLogger({
  format: logDriverFormat,
  transports: [new WFirehose()]
});

const internalLogger = createLogger({
  format: logDriverFormat,
  transports: [new transports.Console()]
});

module.exports = function(secondaryLabel) {
  const defaultOpts = {
    exportLog: false,
    event: ''
  };
  return LOGGING_LEVELS.reduce((exportedMethods, level) => {
    exportedMethods[level] = (message, { exportLog, event } = defaultOpts) => {
      if (exportLog) {
        return exportDriver.log({
          level,
          secondaryLabel,
          exportLog,
          event,
          message
        });
      } else {
        return internalLogger.log({
          level,
          secondaryLabel,
          exportLog,
          event,
          message
        });
      }
    };
    return exportedMethods;
  }, {});
};

const multilineStringify = obj => {
  return JSON.stringify(obj, null, ' ');
};
{'fraction_non_alphanumeric': 0.13754443532950505, 'fraction_numerical': 0.011484823625922888, 'mean_word_length': 2.8545837723919916, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3258933', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1093, 'n_words': 277}