<commit_before>var fs            = require('fs');
var moment        = require('moment');
var config        = require('./../config');
var client        = require('./elasticSearch');
var splunkService = require('./splunk');
var RedisSplunk   = require('./redisSplunk');

var events = require('./database').events;

module.exports = function(eventCode, data) {

  // add timestamp if one isn't passed
  if (data && !data.hasOwnProperty("timestamp")){
    var newTimestamp = new Date().getTime();
    data.timestamp = newTimestamp;
  }
  // moment().toISOString()
  data.timestamp = moment(data.timestamp).toISOString()

  if(eventCode === undefined){
    eventCode = 0;
  }
  data.eventCode = eventCode;
  var uuid = eventCode; //Set the Default to EventCode just in case.
  if (data && data.hasOwnProperty("uuid")){ // if the data has a uuid (and it always should)
        uuid = data.uuid; // set the uuid to the actual uuid.
  }

  if(config.log){
    fs.appendFile('./skynet.txt', JSON.stringify(data) + '\r\n', function (err) {
      if (err) {
        throw err;
      }
    });

    if(config.elasticSearch && config.elasticSearch.hosts){
      if(data._id){
        try{
          data._id.toString();
          delete data._id;
        } catch(e){
          console.log(e);
        }
      }

      client.index({
        // index: "log",
        // type: eventCode,
        index: "skynet_trans_log",
        type: uuid,
        timestamp: data.timestamp,
        body: data
      }, function (error, response) {
        if(error){
          console.log(error);
        }
      });
    }

    RedisSplunk.log(data, function(err){<commit_msg>show erroring message<commit_after>var fs            = require('fs');
var moment        = require('moment');
var config        = require('./../config');
var client        = require('./elasticSearch');
var splunkService = require('./splunk');
var RedisSplunk   = require('./redisSplunk');

var events = require('./database').events;

module.exports = function(eventCode, data) {

  // add timestamp if one isn't passed
  if (data && !data.hasOwnProperty("timestamp")){
    var newTimestamp = new Date().getTime();
    data.timestamp = newTimestamp;
  }
  // moment().toISOString()
  data.timestamp = moment(data.timestamp).toISOString()

  if(eventCode === undefined){
    eventCode = 0;
  }
  data.eventCode = eventCode;
  var uuid = eventCode; //Set the Default to EventCode just in case.
  if (data && data.hasOwnProperty("uuid")){ // if the data has a uuid (and it always should)
        uuid = data.uuid; // set the uuid to the actual uuid.
  }

  if(config.log){
    fs.appendFile('./skynet.txt', JSON.stringify(data) + '\r\n', function (err) {
      if (err) {
        throw err;
      }
    });

    if(config.elasticSearch && config.elasticSearch.hosts){
      if(data._id){
        try{
          data._id.toString();
          delete data._id;
        } catch(e){
          console.log(e);
        }
      }

      var msg = {
        index: "skynet_trans_log",
        type: uuid,
        timestamp: data.timestamp,
        body: data
      };
      client.index(msg, function (error, response) {
        if(error){
          console.log(error, msg);
        }
      });
    }

    RedisSplunk.log(data, function(err){
{'fraction_non_alphanumeric': 0.15166310649984743, 'fraction_numerical': 0.0006103143118706134, 'mean_word_length': 2.278, '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': '1251684', 'n_tokens_mistral': 1002, 'n_tokens_neox': 985, 'n_words': 240}