<commit_before>// Load .env file with all the configuration
require('dotenv').config();

const http = require('http');
const mongoose = require('mongoose');
const config = require('./config');
const app = require('./app');
const logger = require('./logger');

const server = http.createServer(app);

// Use ES6 Promise in Mongoose
mongoose.Promise = global.Promise;

// Catch MongoDB `connect` event
mongoose.connection.on('connected', () => {
    logger.info('MongoDB connected');

    server.listen(app.get('port'), '0.0.0.0');
});

// Catch MongoDB `disconnect` event
mongoose.connection.on('disconnected', () => {
    logger.fatal('MongoDB disconnected');
});

// Catch MongoDB `error` event
mongoose.connection.on('error', (err) => {
    logger.error(`MongoDB error: ${err}`);
});

// Catch Server `listening` event
server.on('listening', () => {
    const { address, port } = server.address();

    logger.info(`Listening on ${address}:${port}`);
});

// Catch server `error` event
server.on('error', (error) => {
    if (error.syscall !== 'listen') {
        throw error;
    }

    const bind = `${typeof port === 'string' ? 'Pipe' : 'Port'} ${app.get('port')}`;

    switch (error.code) {
        case 'EACCES':
            logger.fatal(`${bind} requires elevated privileges`);
            cleanShutDown(1);
            break;

        case 'EADDRINUSE':
            logger.fatal(`${bind} is already in use`);
            cleanShutDown(1);
            break;

        default:
            throw error;
    }
});

// Catch `process termination` event
process.on('SIGINT', cleanShutDown).on('SIGTERM', cleanShutDown);

// Connect to MongoDB
try {
    mongoose.connect(process.env.MONGO_URL, config.mongolab.options);
}
catch (err) {
    logger.fatal(`Sever initialization failed: ${err.message}`);
}

function cleanShutDown(code = 0) {
    mongoose.connection.close(() => {
        logger.info('Mongoose connection with DB is disconnected through app termination');

        process.exit(code);
    });
}
<commit_msg>initialize logger before the app<commit_after>// Load .env file with all the configuration
require('dotenv').config();

const http = require('http');
const mongoose = require('mongoose');
const logger = require('./logger');
const config = require('./config');
const app = require('./app');

const server = http.createServer(app);

// Use ES6 Promise in Mongoose
mongoose.Promise = global.Promise;

// Catch MongoDB `connect` event
mongoose.connection.on('connected', () => {
    logger.info('MongoDB connected');

    server.listen(app.get('port'), '0.0.0.0');
});

// Catch MongoDB `disconnect` event
mongoose.connection.on('disconnected', () => {
    logger.fatal('MongoDB disconnected');
});

// Catch MongoDB `error` event
mongoose.connection.on('error', (err) => {
    logger.error(`MongoDB error: ${err}`);
});

// Catch Server `listening` event
server.on('listening', () => {
    const { address, port } = server.address();

    logger.info(`Listening on ${address}:${port}`);
});

// Catch server `error` event
server.on('error', (error) => {
    if (error.syscall !== 'listen') {
        throw error;
    }

    const bind = `${typeof port === 'string' ? 'Pipe' : 'Port'} ${app.get('port')}`;

    switch (error.code) {
        case 'EACCES':
            logger.fatal(`${bind} requires elevated privileges`);
            cleanShutDown(1);
            break;

        case 'EADDRINUSE':
            logger.fatal(`${bind} is already in use`);
            cleanShutDown(1);
            break;

        default:
            throw error;
    }
});

// Catch `process termination` event
process.on('SIGINT', cleanShutDown).on('SIGTERM', cleanShutDown);

// Connect to MongoDB
try {
    mongoose.connect(process.env.MONGO_URL, config.mongolab.options);
}
catch (err) {
    logger.fatal(`Sever initialization failed: ${err.message}`);
}

function cleanShutDown(code = 0) {
    mongoose.connection.close(() => {
        logger.info('Mongoose connection with DB is disconnected through app termination');

        process.exit(code);
    });
}

{'fraction_non_alphanumeric': 0.17408409146791246, 'fraction_numerical': 0.003934103761986722, 'mean_word_length': 3.2596858638743456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6497797', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1242, 'n_words': 294}