<commit_before>'use strict';

let util = require('util');
let
  bunyan = require('bunyan'),
  chalk = require('chalk');

const colors = {
  log: chalk.bgBlack,
  info: chalk.bgWhite,
  error: chalk.bgRed,
  warn: chalk.bgYellow
};

// In testing bunyan gets mocked and outputted in console with timestamps
function mockLogger (level, type) {
  return function () { // builds something like ERROR: { data: 'hello world' }
    Array.prototype.unshift.call(arguments, colors[level](type.toUpperCase()) + ':');
    util.log.apply(null, arguments);
  };
}

exports = module.exports = function (type) {
  if (process.env.NODE_ENV === 'production') {
    return bunyan.createLogger({ name: type });
  }
  return {
    log: mockLogger('log', type),
    info: mockLogger('info', type),
    error: mockLogger('error', type),
    warn: mockLogger('warn', type)
  };<commit_msg>logger handles better coding errors, there's margin for improvement<commit_after>'use strict';

let util = require('util');
let
  bunyan = require('bunyan'),
  chalk = require('chalk');

const colors = {
  log: chalk.bgBlack,
  info: chalk.bgWhite,
  error: chalk.bgRed,
  warn: chalk.bgYellow
};

// In testing bunyan gets mocked and outputted in console with timestamps
function mockLogger (level, type) {
  return function () { // builds something like ERROR: { data: 'hello world' }
    let args = Array.prototype.filter.call(arguments, function (arg) {
      if (arg instanceof Error) {
        util.log(arg.stack);
        return false;
      }
      return true;
    });
    Array.prototype.unshift.call(args, colors[level](type.toUpperCase()) + ':');
    util.log.apply(null, args);
  };
}

exports = module.exports = function (type) {
  if (process.env.NODE_ENV === 'production') {
    return bunyan.createLogger({ name: type });
  }
  return {
    log: mockLogger('log', type),
    info: mockLogger('info', type),
    error: mockLogger('error', type),
    warn: mockLogger('warn', type)
  };
{'fraction_non_alphanumeric': 0.1520081342145399, 'fraction_numerical': 0.0, 'mean_word_length': 3.7194244604316546, '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': '3907304', 'n_tokens_mistral': 633, 'n_tokens_neox': 617, 'n_words': 166}