<commit_before>var os = require("os"),
    redis = require("redis"),
    hoek = require("hoek"),
    stringifySafe = require("json-stringify-safe"),
    consoleWriter = require("./console-writer"),
    client, cfg, connectionTimer,
    _commonFields = function(log, type){
      var fields = {
        "@timestamp": (new Date()).toISOString(),
        servicetype: cfg.servicetype,
        logname: type,
        formatversion: cfg.versions[type],
        type: cfg.servicetype + "-" + type + "-" + cfg.versions[type],
        host: cfg.host,
        sequencenumber: cfg.sequencenumber,
      };

      return hoek.applyToDefaults(fields, log);
    },
    _dispatch = function(log){
      if(cfg.console){
        consoleWriter.log(log);
      }

      client.rpush(cfg.redis.listname, stringifySafe(log), function(){});
      cfg.sequencenumber++;
    };

module.exports.config = function(config, cb){
  cfg = config;
  cfg.sequencenumber = 1;
  cfg.host = os.hostname();

  client = redis.createClient(cfg.redis.port, cfg.redis.host,
  {
    enable_offline_queue: false
  });

  client.on('error', function (err) {});

  connectionTimer = setTimeout(cb, 2000);
  client.on('connect', function(){
    clearTimeout(connectionTimer);
    cb();
  });
};

module.exports.request = function(request){
  _dispatch(_commonFields({
    method: request.method,
    url: request.path,
    status: request.response.statusCode,
    duration: (Date.now() - request.info.received) * 1000, // just to be compliant. sigh
    durationMilliseconds: Date.now() - request.info.received,
    events: request.getLog(),

    "ot-requestid": request.headers["ot-requestid"],
    "user-agent": request.headers["user-agent"],
    "ot-userid": request.headers["ot-userid"],
    "ot-sessionid": request.headers["ot-sessionid"],
    "ot-referringhost": request.headers["ot-referringhost"],
    "ot-referringservice": request.headers["ot-referringservice"],
    "accept-language": request.headers["accept-language"],
    headers: request.headers, // log anything else that is not pulled up<commit_msg>use the ready event rather than connect to ensure that we can send commands immediately<commit_after>var os = require("os"),
    redis = require("redis"),
    hoek = require("hoek"),
    stringifySafe = require("json-stringify-safe"),
    consoleWriter = require("./console-writer"),
    client, cfg, connectionTimer,
    _commonFields = function(log, type){
      var fields = {
        "@timestamp": (new Date()).toISOString(),
        servicetype: cfg.servicetype,
        logname: type,
        formatversion: cfg.versions[type],
        type: cfg.servicetype + "-" + type + "-" + cfg.versions[type],
        host: cfg.host,
        sequencenumber: cfg.sequencenumber,
      };

      return hoek.applyToDefaults(fields, log);
    },
    _dispatch = function(log){
      if(cfg.console){
        consoleWriter.log(log);
      }

      client.rpush(cfg.redis.listname, stringifySafe(log), function(){});
      cfg.sequencenumber++;
    };

module.exports.config = function(config, cb){
  cfg = config;
  cfg.sequencenumber = 1;
  cfg.host = os.hostname();

  client = redis.createClient(cfg.redis.port, cfg.redis.host, {
    enable_offline_queue: false
  });

  client.on('error', function (err) {});

  connectionTimer = setTimeout(cb, 2000);
  client.on('ready', function(){
    clearTimeout(connectionTimer);
    cb();
  });
};

module.exports.request = function(request){
  _dispatch(_commonFields({
    method: request.method,
    url: request.path,
    status: request.response.statusCode,
    duration: (Date.now() - request.info.received) * 1000, // just to be compliant. sigh
    durationMilliseconds: Date.now() - request.info.received,
    events: request.getLog(),

    "ot-requestid": request.headers["ot-requestid"],
    "user-agent": request.headers["user-agent"],
    "ot-userid": request.headers["ot-userid"],
    "ot-sessionid": request.headers["ot-sessionid"],
    "ot-referringhost": request.headers["ot-referringhost"],
    "ot-referringservice": request.headers["ot-referringservice"],
    "accept-language": request.headers["accept-language"],
    headers: request.headers, // log anything else that is not pulled up
{'fraction_non_alphanumeric': 0.15614617940199335, 'fraction_numerical': 0.004271476032273375, 'mean_word_length': 3.4415173867228663, 'pattern_counts': {'":': 16, '<': 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': '6384795', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1280, 'n_words': 249}