<commit_before>const _ = require('underscore');
const sentry = require('winston-sentry');
const winston = require('winston');
const slack = require('winston-slacker');
const colors = {
  debug: 'white',
  info: 'green',
  warn: 'yellow',
  error: 'red'
};

const levels = {
  debug: 0,
  info: 1,
  warn: 2,
  error: 3
};

var logger = new winston.Logger({
  colors: colors,
  levels: levels
});

var sentryDsn = null;

var slackOptions = {
  webhook: '',
  channel: '#integrationtesting',
  username: 'stagedrive'
};

const transports = {
  console: {
    transport: winston.transports.Console,
    args: {
      level: 'info',
      colorize: true,
      timestamp: true,
      handleExceptions: true,
      prettyPrint: true,
      silent: false
    }
  },
  file: {
    transport: winston.transports.File,
    args: {
      filename: 'app.log',
      level: 'debug',
      colorize: true,
      timestamp: true,
      handleExceptions: true
    }
  },
  slack: {
    transport: slack,
    args: {
      level: 'info',
      colorize: true,
      timestamp: true,
      handleExceptions: true,
      prettyPrint: true,
      silent: false
    }
  },
  sentry: {
    transport: sentry,
    args: {
      level: 'error',
      colorize: true,
      timestamp: true,
      handleExceptions: true,
      prettyPrint: true,
      silent: false
    }
  }
};

var defaultConsoleFunctions = {};

/**
 * Overrides the default console logging methods (debug, log, warn and error) to pass arguments to releveant
 * winston logger functions
 */
function start() {
  // Override the all of the console methods with the Winstons logger methods
  Object.keys(levels).forEach(function (level) {
    defaultConsoleFunctions[level] = {
      name: level,
      func: console[level]
    };
    console[level] = function () {
      logger[level].apply(level, arguments);
    };
  });
  // Override the console log and send it through to the logger info method.
  defaultConsoleFunctions.log = {
    name: 'log',
    func: console.log
  };
  console.log =  function () {
    logger.info.apply('info', arguments);
  };
  return module.exports;
}

/**
 * Restores default console method behavior
 */
function stop() {
  Object.keys(defaultConsoleFunctions).forEach(function (level) {
    console[level] = defaultConsoleFunctions[level].func;
  });
  return module.exports;
}

/**
 * Removes a transports from Winston.
 * @param {string} Name of the transport to remove
 * @param {object} Sentry dns and enabled status
 */
function removeLogger(transportName) {
  logger.remove(transportName);
}

/**
 * Handles the creation of the Sentry transport
 * @params {string} Name of the transport
 */
function handleSentryTransport(transport) {
  if (!module.exports.sentryDsn) {
    console.error('No Sentry dsn defined');
    return;
  }
  logger.add(module.exports.transports[transport].transport,
              _.extend(module.exports.transports[transport].args, {
                dsn: module.exports.sentryDsn,
                enabled: true
              }));
}

/**
 * Handles the creation of the Slack transport
 * @params {string} Name of the transport
 */
function handleSlackTransport(transport) {
  if (!module.exports.slackOptions.webhook || !module.exports.slackOptions.channel) {
    console.error('Missing required slack options');
    return;
  }
  logger.add(module.exports.transports[transport].transport,
              _.extend(module.exports.transports[transport].args,
              module.exports.slackOptions));
}<commit_msg>Removed requirement to specify slack channel<commit_after>const _ = require('underscore');
const sentry = require('winston-sentry');
const winston = require('winston');
const slack = require('winston-slacker');
const colors = {
  debug: 'white',
  info: 'green',
  warn: 'yellow',
  error: 'red'
};

const levels = {
  debug: 0,
  info: 1,
  warn: 2,
  error: 3
};

var logger = new winston.Logger({
  colors: colors,
  levels: levels
});

var sentryDsn = null;

var slackOptions = {
  webhook: '',
  channel: '#integrationtesting',
  username: 'stagedrive'
};

const transports = {
  console: {
    transport: winston.transports.Console,
    args: {
      level: 'info',
      colorize: true,
      timestamp: true,
      handleExceptions: true,
      prettyPrint: true,
      silent: false
    }
  },
  file: {
    transport: winston.transports.File,
    args: {
      filename: 'app.log',
      level: 'debug',
      colorize: true,
      timestamp: true,
      handleExceptions: true
    }
  },
  slack: {
    transport: slack,
    args: {
      level: 'info',
      colorize: true,
      timestamp: true,
      handleExceptions: true,
      prettyPrint: true,
      silent: false
    }
  },
  sentry: {
    transport: sentry,
    args: {
      level: 'error',
      colorize: true,
      timestamp: true,
      handleExceptions: true,
      prettyPrint: true,
      silent: false
    }
  }
};

var defaultConsoleFunctions = {};

/**
 * Overrides the default console logging methods (debug, log, warn and error) to pass arguments to releveant
 * winston logger functions
 */
function start() {
  // Override the all of the console methods with the Winstons logger methods
  Object.keys(levels).forEach(function (level) {
    defaultConsoleFunctions[level] = {
      name: level,
      func: console[level]
    };
    console[level] = function () {
      logger[level].apply(level, arguments);
    };
  });
  // Override the console log and send it through to the logger info method.
  defaultConsoleFunctions.log = {
    name: 'log',
    func: console.log
  };
  console.log =  function () {
    logger.info.apply('info', arguments);
  };
  return module.exports;
}

/**
 * Restores default console method behavior
 */
function stop() {
  Object.keys(defaultConsoleFunctions).forEach(function (level) {
    console[level] = defaultConsoleFunctions[level].func;
  });
  return module.exports;
}

/**
 * Removes a transports from Winston.
 * @param {string} Name of the transport to remove
 * @param {object} Sentry dns and enabled status
 */
function removeLogger(transportName) {
  logger.remove(transportName);
}

/**
 * Handles the creation of the Sentry transport
 * @params {string} Name of the transport
 */
function handleSentryTransport(transport) {
  if (!module.exports.sentryDsn) {
    console.error('No Sentry dsn defined');
    return;
  }
  logger.add(module.exports.transports[transport].transport,
              _.extend(module.exports.transports[transport].args, {
                dsn: module.exports.sentryDsn,
                enabled: true
              }));
}

/**
 * Handles the creation of the Slack transport
 * @params {string} Name of the transport
 */
function handleSlackTransport(transport) {
  if (!module.exports.slackOptions.webhook) {
    console.error('Missing required slack options');
    return;
  }
  logger.add(module.exports.transports[transport].transport,
              _.extend(module.exports.transports[transport].args,
              module.exports.slackOptions));
}
{'fraction_non_alphanumeric': 0.12284942414332432, 'fraction_numerical': 0.0011374946679937438, 'mean_word_length': 2.9762577727529678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '429237', 'n_tokens_mistral': 2127, 'n_tokens_neox': 2096, 'n_words': 550}