<commit_before>'use strict';

// Load modules

var Path = require('path');
var HeapDump = require('heapdump');
var Hoek = require('hoek');
var Utils = require('./utils');


// Declare internals

var internals = {
    initialized: false,
    defaults: {
        logPath: Path.join(__dirname, '..', 'poop.log'),
        writeStreamOptions: { flags: 'w' }
    }
};


module.exports.register = function (server, options, next) {

    var settings = Hoek.applyToDefaults(internals.defaults, options || {});

    if (internals.initialized) {
        return next();
    }

    internals.initialized = true;

    process.once('uncaughtException', function (err) {

        HeapDump.writeSnapshot();
        Utils.log(err, {
            logPath: settings.logPath,
            writeStreamOptions: settings.writeStreamOptions
        }, function () {

            process.exit(1);
        });
    });

    process.on('SIGUSR1', function () {

        HeapDump.writeSnapshot();
    });

    return next();
};


module.exports.register.attributes = {
    pkg: require('../package.json')
};<commit_msg>Add setting for heapdump folder and change default folder to the app folder (instead of plugin)<commit_after>'use strict';

// Load modules

var Path = require('path');
var HeapDump = require('heapdump');
var Hoek = require('hoek');
var Utils = require('./utils');


// Declare internals

var internals = {
    initialized: false,
    defaults: {
        logPath: Path.join(Path.dirname(process.mainModule.filename), 'poop.log'),
        heapdumpFolder: Path.join(Path.dirname(process.mainModule.filename)),
        writeStreamOptions: { flags: 'w' }
    }
};


module.exports.register = function (server, options, next) {

    var settings = Hoek.applyToDefaults(internals.defaults, options || {});

    if (internals.initialized) {
        return next();
    }

    internals.initialized = true;

    process.once('uncaughtException', function (err) {

        HeapDump.writeSnapshot(Path.join(settings.heapdumpFolder, Date.now() + '.heapsnapshot'));
        Utils.log(err, {
            logPath: settings.logPath,
            writeStreamOptions: settings.writeStreamOptions
        }, function () {

            process.exit(1);
        });
    });

    process.on('SIGUSR1', function () {

        HeapDump.writeSnapshot(Path.join(settings.heapdumpFolder, Date.now() + '.heapsnapshot'));
    });

    return next();
};


module.exports.register.attributes = {
    pkg: require('../package.json')
};
{'fraction_non_alphanumeric': 0.14859437751004015, 'fraction_numerical': 0.001606425702811245, 'mean_word_length': 2.88006230529595, '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': '169900', 'n_tokens_mistral': 753, 'n_tokens_neox': 726, 'n_words': 147}