<commit_before>'use strict';

var os = require('os');
var url = require('url');
var cluster = require('cluster');
var bunyan = require('bunyan');
var deck = require('deck');
var exitHook = require('exit-hook');

var args = process.argv.slice(2);
var config = args[0];
if (!config || config === 'undefined') throw new Error('Missing config!');

config = JSON.parse(config);

process.on('message', function(msg) {
  if (msg.type === 'config' && msg.config) config = msg.config;
});

// Responds to the cluster disconnect signal/event from the master process
exitHook(function (next) { next(); });

// todo : we could move the log creation out to the service init file.
//        and/or use a modified consule.log object or pico as default.
var log = bunyan.createLogger({
  name: config.name,
  version: config.version,
  worker: cluster.isWorker ? cluster.worker.id : 'unknown',
  level: config.log_level
});

function getURL (service, path, query) {
  var record = deck.pick(config[service] || []);
  if (!record || !record.host) {
    log.warn(new Error('Didn\'t find a record for ' + service));
    return;
  }

  var uo = url.parse('http://' + record.host + ':' + record.port);
  if (path) {
    if (Array.isArray(path)) path = path.join('/');
    uo.pathname = path;
  }
  if (query) {
    uo.query = query;
  }
  return url.format(uo);
}

function clientId () {
  return [config.name, 'v' + config.version, config.environment, process.pid, os.hostname()].join('_');
}

config.log = log;
config.getURL = getURL;
config.clientId = clientId;
module.exports = config;<commit_msg>Using stdSerializers to better serializing an error<commit_after>'use strict';

var os = require('os');
var url = require('url');
var cluster = require('cluster');
var bunyan = require('bunyan');
var deck = require('deck');
var exitHook = require('exit-hook');

var args = process.argv.slice(2);
var config = args[0];
if (!config || config === 'undefined') throw new Error('Missing config!');

config = JSON.parse(config);

process.on('message', function(msg) {
  if (msg.type === 'config' && msg.config) config = msg.config;
});

// Responds to the cluster disconnect signal/event from the master process
exitHook(function (next) { next(); });

// todo : we could move the log creation out to the service init file.
//        and/or use a modified consule.log object or pico as default.
var log = bunyan.createLogger({
  name: config.name,
  version: config.version,
  worker: cluster.isWorker ? cluster.worker.id : 'unknown',
  level: config.log_level,
  serializers: bunyan.stdSerializers
});

function getURL (service, path, query) {
  var record = deck.pick(config[service] || []);
  if (!record || !record.host) {
    log.warn(new Error('Didn\'t find a record for ' + service));
    return;
  }

  var uo = url.parse('http://' + record.host + ':' + record.port);
  if (path) {
    if (Array.isArray(path)) path = path.join('/');
    uo.pathname = path;
  }
  if (query) {
    uo.query = query;
  }
  return url.format(uo);
}

function clientId () {
  return [config.name, 'v' + config.version, config.environment, process.pid, os.hostname()].join('_');
}

config.log = log;
config.getURL = getURL;
config.clientId = clientId;
module.exports = config;
{'fraction_non_alphanumeric': 0.16779975278121137, 'fraction_numerical': 0.0012360939431396785, 'mean_word_length': 3.94954128440367, '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': '1325875', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1036, 'n_words': 303}