<commit_before>/*
 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
 *
 * Main entry-point for the VMs API.
 */

var path = require('path');
var fs = require('fs');

var VMAPI = require('./lib/vmapi');

var VERSION = false;


/**
 * Returns the current semver version stored in CloudAPI's package.json.
 * This is used to set in the API versioning and in the Server header.
 *
 * @return {String} version.
 */
function version() {
    if (!VERSION) {
        var pkg = fs.readFileSync(__dirname + '/package.json', 'utf8');
        VERSION = JSON.parse(pkg).version;
    }

    return VERSION;
}


/*
 * Loads and parse the configuration file at config.json
 */
function loadConfig() {
    var configPath = path.join(__dirname, 'config.json');

    if (!fs.existsSync(configPath)) {
        console.error('Config file not found: ' + configPath +
          ' does not exist. Aborting.');
        process.exit(1);
    }

    var theConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
    return theConfig;
}

var config = loadConfig();
config.version = version() || '7.0.0';


var vmapi;

try {
    vmapi = new VMAPI(config);
    vmapi.init();
} catch (e) {
    console.error('Error produced when initializing VMAPI services');
    console.error(e.message);
    console.error(e.stack);
}

vmapi.once('ready', function () {
    vmapi.log.info('All services are up');
});

process.on('uncaughtException', function (err) {
    vmapi.log.error('Uncaught Exception', err);
    vmapi.log.error(err.stack);
});


// Increase/decrease loggers levels using SIGUSR2/SIGUSR1:
var sigyan = require('sigyan');
sigyan.add([vmapi.log]);<commit_msg>ZAPI-265: uncaughtException is not printing the error stack<commit_after>/*
 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
 *
 * Main entry-point for the VMs API.
 */

var path = require('path');
var fs = require('fs');

var VMAPI = require('./lib/vmapi');

var VERSION = false;


/**
 * Returns the current semver version stored in CloudAPI's package.json.
 * This is used to set in the API versioning and in the Server header.
 *
 * @return {String} version.
 */
function version() {
    if (!VERSION) {
        var pkg = fs.readFileSync(__dirname + '/package.json', 'utf8');
        VERSION = JSON.parse(pkg).version;
    }

    return VERSION;
}


/*
 * Loads and parse the configuration file at config.json
 */
function loadConfig() {
    var configPath = path.join(__dirname, 'config.json');

    if (!fs.existsSync(configPath)) {
        console.error('Config file not found: ' + configPath +
          ' does not exist. Aborting.');
        process.exit(1);
    }

    var theConfig = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
    return theConfig;
}

var config = loadConfig();
config.version = version() || '7.0.0';


var vmapi;

try {
    vmapi = new VMAPI(config);
    vmapi.init();
} catch (e) {
    console.error('Error produced when initializing VMAPI services');
    console.error(e.message);
    console.error(e.stack);
}

vmapi.once('ready', function () {
    vmapi.log.info('All services are up');
});

process.on('uncaughtException', function (err) {
    vmapi.log.error(err, 'Uncaught Exception');
});


// Increase/decrease loggers levels using SIGUSR2/SIGUSR1:
var sigyan = require('sigyan');
sigyan.add([vmapi.log]);
{'fraction_non_alphanumeric': 0.15081768625075712, 'fraction_numerical': 0.00817686250757117, 'mean_word_length': 3.3063885267275097, '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': '6733021', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1068, 'n_words': 291}