<commit_before>/**
 * tty-lean.js: logger.js
 * Copyright (c) 2012-2014, <NAME> (MIT License)
 * Copyright (c) 2014, The University of Melbourne
 */

var slice = Array.prototype.slice
  , isatty = require('tty').isatty;

/**
 * Logger
 */

function constructor(consoleLike) {

  function loggingF(col, level) {
    return function() {
      var args = slice.call(arguments);
      
      if (typeof(args[0]) !== 'string') {
        args.unshift('');
      }
    
      args[0] = '\x1b['
        + col
        + 'm['
        + logger.prefix
        + ']\x1b[m '
        + args[0];
      
      if (!logger.isatty[level]) {
        args[0] = args[0].replace(/\x1b\[(?:\d+(?:;\d+)*)?m/g, '');
      }
    
      return consoleLike[level].apply(consoleLike, args);
    };
  }
  
  var logger = function() {
    return logger[arguments[0]].apply(logger, slice.call(arguments, 1));
  };

  // See http://en.wikipedia.org/wiki/File_descriptor for more info.
  // console.log   writes to STDOUT (fd 1)
  // console.error writes to STDERR (fd 2)
  logger.isatty = {
    log: isatty(1),
    error: isatty(2)
  };
  
  logger.prefix = 'tty-lean.js';
  
  logger.log = loggingF(34, 'log');
  logger.warning = loggingF(31, 'error');
  logger.error = loggingF(41, 'error');
  
  logger.console = consoleLike;
  
  return logger;
}

/**
 * Expose
 */

module.exports = constructor;
<commit_msg>Using slightly more repetition to avoid crazy regex.<commit_after>/**
 * tty-lean.js: logger.js
 * Copyright (c) 2012-2014, <NAME> (MIT License)
 * Copyright (c) 2014, The University of Melbourne
 */

var slice = Array.prototype.slice
  , isatty = require('tty').isatty;

/**
 * Logger
 */

function constructor(consoleLike) {

  function loggingF(col, level) {
    return function() {
      var args = slice.call(arguments);
      
      if (typeof(args[0]) !== 'string') {
        args.unshift('');
      }
    
      if (logger.isatty[level]) {
        // Use color to indicate log level
        args[0] = '\x1b['
          + col
          + 'm['
          + logger.prefix
          + ']\x1b[m '
          + args[0];
      } else {
        // Omit color and log levels
        args[0] = '[' + logger.prefix + '] ' + args[0];
      }
    
      return consoleLike[level].apply(consoleLike, args);
    };
  }
  
  var logger = function() {
    return logger[arguments[0]].apply(logger, slice.call(arguments, 1));
  };

  // See http://en.wikipedia.org/wiki/File_descriptor for more info.
  // console.log   writes to STDOUT (fd 1)
  // console.error writes to STDERR (fd 2)
  logger.isatty = {
    log: isatty(1),
    error: isatty(2)
  };
  
  logger.prefix = 'tty-lean.js';
  
  logger.log = loggingF(34, 'log');
  logger.warning = loggingF(31, 'error');
  logger.error = loggingF(41, 'error');
  
  logger.console = consoleLike;
  
  return logger;
}

/**
 * Expose
 */

module.exports = constructor;

{'fraction_non_alphanumeric': 0.1678224687933426, 'fraction_numerical': 0.021844660194174758, 'mean_word_length': 2.331408775981524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2429347', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1000, 'n_words': 214}