<commit_before>/**
 * Copyright (c) 2013-2016 Memba Sarl. All rights reserved.
 * Sources at https://github.com/Memba
 */

/* jshint node: true */

'use strict';

var assert = require('assert');
var config = require('../config');
var httpStatus = require('../lib/httpStatus');
var logger = require('../lib/logger');
var utils = require('../lib/utils');

var DEBUG = config.get('debug');
var RX_LEVEL = /^(DEBUG|INFO|WARN|ERROR|CRIT)$/i;

module.exports = {

    /**
     * Add a log entry
     * @param req
     * @param res
     * @param next
     */
    createEntry: function (req, res, next) {

        // Assert body (after being parsed by body-parser)
        var body = req.body;

        if (utils.isObject(body) &&
            typeof body.date === 'string' &&
            RX_LEVEL.test(body.level) &&
            typeof body.message === 'string') { // We could also check that we have either (i) module + method, or (ii) error stack

            // Read the trace from headers
            req.trace = req.headers['x-trace-id'];

            // Log the request
            body.request = req;
            logger[body.level.toLowerCase()](body);

            // Return ok
            res.status(httpStatus.created).end();

        }

        // Return ok in all circumstances
        res.status(httpStatus.created).end();
    }
};<commit_msg>Fixed issue with double res.end()<commit_after>/**
 * Copyright (c) 2013-2016 Memba Sarl. All rights reserved.
 * Sources at https://github.com/Memba
 */

/* jshint node: true */

'use strict';

var assert = require('assert');
var config = require('../config');
var httpStatus = require('../lib/httpStatus');
var logger = require('../lib/logger');
var utils = require('../lib/utils');

var DEBUG = config.get('debug');
var RX_LEVEL = /^(DEBUG|INFO|WARN|ERROR|CRIT)$/i;

module.exports = {

    /**
     * Add a log entry
     * @param req
     * @param res
     * @param next
     */
    createEntry: function (req, res, next) {

        // Assert body (after being parsed by body-parser)
        var body = req.body;

        if (utils.isObject(body) &&
            typeof body.date === 'string' &&
            RX_LEVEL.test(body.level) &&
            typeof body.message === 'string') { // We could also check that we have either (i) module + method, or (ii) error stack

            // Read the trace from headers
            req.trace = req.headers['x-trace-id'];

            // Log the request
            body.request = req;
            logger[body.level.toLowerCase()](body);
        }

        // Return ok in all circumstances
        res.status(httpStatus.created).end();
    }
};
{'fraction_non_alphanumeric': 0.15422508525956802, 'fraction_numerical': 0.0060629026146267525, 'mean_word_length': 2.1466030989272946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2107822', 'n_tokens_mistral': 796, 'n_tokens_neox': 765, 'n_words': 221}