<commit_before>'use strict';

var winston      = require('winston')
  , fs           = require('fs')
  , config       = require('../config')
  , logDirectory = __dirname + '/../logs'
  , infoFile     = __dirname + '/../logs/info.log'
  , warnFile     = __dirname + '/../logs/warn.log'
  , errorFile    = __dirname + '/../logs/error.log'
  , transports   = []
  ;

if (config.logToFile) {
  // ensure directories and files exist for logging
  var logsExist = fs.existsSync(logDirectory);

  if (!logsExist) {
    fs.mkdirSync(logDirectory);

    var firstLine = "File Created at: " + new Date().toString() + "\n\n";

    fs.writeFileSync(infoFile, firstLine);
    fs.writeFileSync(warnFile, firstLine);
    fs.writeFileSync(errorFile, firstLine);
  }

  transports.push(new(winston.transports.File)({
    name: 'file#info',
    timestamp: true,
    filename: infoFile,
    level: 'info',
    handleExceptions: false
  }));

  transports.push(new(winston.transports.File)({
    name: 'file#warn',
    timestamp: true,
    filename: warnFile,
    level: 'warn',
    handleExceptions: false
  }));

  transports.push(new(winston.transports.File)({
    name: 'file#error',
    timestamp: true,
    filename: errorFile,
    level: 'error',
    handleExceptions: true
  }));
} else {

  transports.push(new(winston.transports.Console)({
    colorize: true,
    handleExceptions: true
  }));
}

var logger = new(winston.Logger)({
  transports: transports,
  exitOnError: false
});

module.exports = logger;<commit_msg>update logging to each file<commit_after>'use strict';

var winston      = require('winston')
  , fs           = require('fs')
  , config       = require('../config')
  , logDirectory = __dirname + '/../logs'
  , debugFile    = __dirname + '/../logs/debug.log'
  , infoFile     = __dirname + '/../logs/info.log'
  , warnFile     = __dirname + '/../logs/warn.log'
  , errorFile    = __dirname + '/../logs/error.log'
  , exports      = {}
  ;

if (config.logToFile) {
  // ensure directories and files exist for logging
  var logsExist = fs.existsSync(logDirectory);

  if (!logsExist) {
    fs.mkdirSync(logDirectory);

    var firstLine = "File Created at: " + new Date().toString() + "\n\n";

    fs.writeFileSync(debugFile, firstLine);
    fs.writeFileSync(infoFile, firstLine);
    fs.writeFileSync(warnFile, firstLine);
    fs.writeFileSync(errorFile, firstLine);
  }

  var debug = new winston.Logger({
    levels: {
      debug: 0
    },
    transports: [
      new(winston.transports.File)({
        filename: debugFile,
        level: 'debug',
        handleExceptions: false
      })
    ]
  });

  var info = new winston.Logger({
    levels: {
      info: 1
    },
    transports: [
      new(winston.transports.File)({
        filename: infoFile,
        level: 'info',
        handleExceptions: false
      })
    ]
  });

  var warn = new winston.Logger({
    levels: {
      warn: 2
    },
    transports: [
      new(winston.transports.File)({
        filename: warnFile,
        level: 'warn',
        handleExceptions: false
      })
    ]
  });

  var error = new winston.Logger({
    levels: {
      error: 3
    },
    transports: [
      new(winston.transports.File)({
        filename: errorFile,
        level: 'error',
        handleExceptions: true
      })
    ]
  });

  exports = {
    debug: function(msg) {
      debug.debug(msg);
    },
    info: function(msg) {
      info.info(msg);
    },
    warn: function(msg) {
      warn.warn(msg);
    },
    error: function(msg) {
      error.error(msg);
    },
    log: function(level, msg) {
      var lvl = exports[level];
      lvl(msg);
    }
  };

} else {

  exports = new(winston.Logger)({
    transports: [new(winston.transports.Console)({
      colorize: true,
      handleExceptions: true
    })],
    exitOnError: false
  });
}

module.exports = exports;
{'fraction_non_alphanumeric': 0.15142857142857144, 'fraction_numerical': 0.001038961038961039, 'mean_word_length': 2.4322638146167557, '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': '2521900', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1263, 'n_words': 251}