<commit_before>// Copyright 2012 Joyent, Inc.  All rights reserved.

var cluster = require('cluster');
var os = require('os');
var path = require('path');

var d = require('dtrace-provider');
var Logger = require('bunyan');
var nopt = require('nopt');

var app = require('./lib').app;



///--- Globals

var DEFAULT_CFG = __dirname + '/etc/cloudapi.config.json';
var DTP = d.createDTraceProvider('cloudapi');
var LOG;
var PARSED;


var opts = {
    'debug': Boolean,
    'file': String,
    'port': Number,
    'help': Boolean
};

var shortOpts = {
    'd': ['--debug'],
    'f': ['--file'],
    'p': ['--port'],
    'h': ['--help']
};



///--- Helpers

function usage(code, message) {
  var _opts = '';
  Object.keys(shortOpts).forEach(function(k) {
    var longOpt = shortOpts[k][0].replace('--', '');
    var type = opts[longOpt].name || 'string';
    if (type && type === 'boolean') type = '';
    type = type.toLowerCase();

    _opts += ' [--' + longOpt + ' ' + type + ']';
  });

  var msg = (message ? message + '\n' : '') +
    'usage: ' + path.basename(process.argv[1]) + _opts;

  process.stderr.write(msg + '\n');
  process.exit(code);
}


function run() {
    var server = app.createServer({
        config: PARSED.file || DEFAULT_CFG,
        overrides: PARSED,
        log: LOG,
        dtrace: DTP
    });

    DTP.enable();
    server.start(function() {
        LOG.info('CloudAPI listening at %s', server.url);
    });

    return server;
}

///--- Mainline

PARSED = nopt(opts, shortOpts, process.argv, 2);
if (PARSED.help)
    usage(0);

LOG = new Logger({
    level: (PARSED.debug ? 'trace' : 'info'),
    name: 'CloudAPI',
    stream: process.stderr
});

if (PARSED.debug) {
    run();
} else if (cluster.isMaster) {
    for (var i = 0; i < os.cpus().length; i++)
        cluster.fork();

    cluster.on('death', function(worker) {
        LOG.error({worker: worker}, 'worker %d exited');
    });

} else {
    run();
}<commit_msg>CloudAPI missing bunyan serializers<commit_after>// Copyright 2012 Joyent, Inc.  All rights reserved.

var cluster = require('cluster');
var os = require('os');
var path = require('path');

var d = require('dtrace-provider');
var Logger = require('bunyan');
var nopt = require('nopt');

var app = require('./lib').app;



///--- Globals

var DEFAULT_CFG = __dirname + '/etc/cloudapi.config.json';
var DTP = d.createDTraceProvider('cloudapi');
var LOG;
var PARSED;


var opts = {
    'debug': Boolean,
    'file': String,
    'port': Number,
    'help': Boolean
};

var shortOpts = {
    'd': ['--debug'],
    'f': ['--file'],
    'p': ['--port'],
    'h': ['--help']
};



///--- Helpers

function usage(code, message) {
  var _opts = '';
  Object.keys(shortOpts).forEach(function(k) {
    var longOpt = shortOpts[k][0].replace('--', '');
    var type = opts[longOpt].name || 'string';
    if (type && type === 'boolean') type = '';
    type = type.toLowerCase();

    _opts += ' [--' + longOpt + ' ' + type + ']';
  });

  var msg = (message ? message + '\n' : '') +
    'usage: ' + path.basename(process.argv[1]) + _opts;

  process.stderr.write(msg + '\n');
  process.exit(code);
}


function run() {
    var server = app.createServer({
        config: PARSED.file || DEFAULT_CFG,
        overrides: PARSED,
        log: LOG,
        dtrace: DTP
    });

    DTP.enable();
    server.start(function() {
        LOG.info('CloudAPI listening at %s', server.url);
    });

    return server;
}

///--- Mainline

PARSED = nopt(opts, shortOpts, process.argv, 2);
if (PARSED.help)
    usage(0);

LOG = new Logger({
    level: (PARSED.debug ? 'trace' : 'info'),
    name: 'CloudAPI',
    stream: process.stderr,
    serializers: {
        err: Logger.stdSerializers.err,
        req: Logger.stdSerializers.req,
        res: restify.bunyan.serializers.response
    }
});

if (PARSED.debug) {
    run();
} else if (cluster.isMaster) {
    for (var i = 0; i < os.cpus().length; i++)
        cluster.fork();

    cluster.on('death', function(worker) {
        LOG.error({worker: worker}, 'worker %d exited');
    });

} else {
    run();
}
{'fraction_non_alphanumeric': 0.202203182374541, 'fraction_numerical': 0.004406364749082008, 'mean_word_length': 2.7349177330895795, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6823329', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1422, 'n_words': 334}