<commit_before>//
// Simple logging module
//
var logger = exports;

var util = require('util'),
    colors = require('colors');

var levels = logger.levels = {
  info: 'green',
  data: 'grey',
  warn: 'yellow',
  error: 'red',
  event: 'grey',
  exec: 'grey',
  help: 'cyan',
  hook: 'magenta'
};

//
// logger may be set to silent at anytime by setting logger.silent=true
//
logger.silent = false;

logger.log = function (/* level, a, b, c, ... */) {
  var args = [].slice.call(arguments),
      level = args.shift();
  if(!logger.silent) {
    process.stdout.write(
      level[levels[level]] + ': ' + util.format.apply(null, args) + '\n'
    );
  }
}

function hoistLevels (levels) {
  Object.keys(levels).forEach(function(level){
    logger[level] = function (/* a, b, c, ... */) {
      var args = [].slice.call(arguments);
      logger.log.apply(null, [ level ].concat(args));
    }
  });
};

function pad (str, count) {
  for (var i = 0; i < count; i++) {
    str += " ";
  }
  return str;
};

logger.put = function (input, callback) {
  if(typeof callback !== "function") {
    callback = function () {};
  }
  if (Array.isArray(input)) {
    //
    // headers
    //
    var headers = [];
    Object.keys(input[0]).forEach(function(prop){
      headers.push(prop);
    })
    logger.data(headers.join(' '));
    //
    // rows
    //
    input.forEach(function(item){
      logger.put(item);
    });
    return callback(null, input);
  }

  if (typeof input === 'object') {
    // input, showHidden, depth, colors
    util.inspect(input, false, 1, true).split('\n').forEach(function (l) {
      logger.data(l);
    });
    return callback(null, input);
  }

  logger.data(input);
  return callback(null, input);
};

hoistLevels(levels);<commit_msg>[ux] logger.put no longer crashes when passed arrays of non-objects<commit_after>//
// Simple logging module
//
var logger = exports;

var util = require('util'),
    colors = require('colors');

var levels = logger.levels = {
  info: 'green',
  data: 'grey',
  warn: 'yellow',
  error: 'red',
  event: 'grey',
  exec: 'grey',
  help: 'cyan',
  hook: 'magenta'
};

//
// logger may be set to silent at anytime by setting logger.silent=true
//
logger.silent = false;

logger.log = function (/* level, a, b, c, ... */) {
  var args = [].slice.call(arguments),
      level = args.shift();
  if(!logger.silent) {
    process.stdout.write(
      level[levels[level]] + ': ' + util.format.apply(null, args) + '\n'
    );
  }
}

function hoistLevels (levels) {
  Object.keys(levels).forEach(function(level){
    logger[level] = function (/* a, b, c, ... */) {
      var args = [].slice.call(arguments);
      logger.log.apply(null, [ level ].concat(args));
    }
  });
};

function pad (str, count) {
  for (var i = 0; i < count; i++) {
    str += " ";
  }
  return str;
};

logger.put = function (input, callback) {
  if(typeof callback !== "function") {
    callback = function () {};
  }
  //
  // TODO: Print arrays of homogeneous objects in tabular form
  //
  /*
  if (Array.isArray(input)) {
    //
    // headers
    //
    var headers = [];
    Object.keys(input[0]).forEach(function(prop){
      headers.push(prop);
    })
    logger.data(headers.join(' '));
    //
    // rows
    //
    input.forEach(function(item){
      logger.put(item);
    });
    return callback(null, input);
  }
  */

  // input, showHidden, depth, colors
  util.inspect(input, false, 1, true).split('\n').forEach(function (l) {
    logger.data(l);
  });
  return callback(null, input);
  return callback(null, input);
};

hoistLevels(levels);
{'fraction_non_alphanumeric': 0.1926836079307456, 'fraction_numerical': 0.0016755096341803965, 'mean_word_length': 2.6776180698151952, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1491275', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1228, 'n_words': 282}