<commit_before>var rabbit = require('./rabbit');
var hostInfo = require('./hostInfo');
var _ = require('lodash');

var exchange = null;
var pendingEntries = [];

var debugType = 'DEBUG';
var infoType = 'INFO';
var warnType = 'WARN';
var errorType = 'ERROR';

module.exports = {
	configure: function(rabbitConfig) {
		var connecting = rabbit.configure(rabbitConfig);
		connecting.subscribe(function(_exchange_) {
			exchange = _exchange_;

			if (_.any(pendingEntries)) {
				pendingEntries.forEach(function(entry) {
					exchange.publish(entry.type, entry);
				});

				pendingEntries = [];
			}
		}, function() {
			exchange = null;
		});
	},

	debug: function(entry) {
		entry = inflateMessage(entry);
		entry.type = debugType;
		log(entry);
	},
	info: function(entry) {
		entry = inflateMessage(entry);
		entry.type = infoType;
		log(entry);
	},
	warn: function(entry) {
		entry = inflateMessage(entry);
		entry.type = warnType;
		log(entry);
	},
	error: function(entry) {
		entry = inflateMessage(entry);
		entry.type = errorType;
		log(entry);
	},
};

function inflateMessage(entry) {
	if (!_.isObject(entry)) {
		entry = {
			message: entry,
		};
	}

	return entry;
}

function log(entry) {
	entry.host = hostInfo.get();
	entry.timestamp = new Date();

	if (exchange) {<commit_msg>Put the log entry data inside of a message property. This keeps it isolated, which prevents name collisions and keeps the log entries cleaner. There is now no need to "inflate" log messages, just put the contents of the entry in the message property.<commit_after>var rabbit = require('./rabbit');
var hostInfo = require('./hostInfo');
var _ = require('lodash');

var exchange = null;
var pendingEntries = [];

var debugType = 'DEBUG';
var infoType = 'INFO';
var warnType = 'WARN';
var errorType = 'ERROR';

module.exports = {
	configure: function(rabbitConfig) {
		var connecting = rabbit.configure(rabbitConfig);
		connecting.subscribe(function(_exchange_) {
			exchange = _exchange_;

			if (_.any(pendingEntries)) {
				pendingEntries.forEach(function(entry) {
					exchange.publish(entry.type, entry);
				});

				pendingEntries = [];
			}
		}, function() {
			exchange = null;
		});
	},

	debug: function(message) {
		var logEntry = {
			message: message,
			type: debugType,
		};
		log(logEntry);
	},
	info: function(message) {
		var logEntry = {
			message: message,
			type: infoType,
		};
		log(logEntry);
	},
	warn: function(message) {
		var logEntry = {
			message: message,
			type: warnType,
		};
		log(logEntry);
	},
	error: function(message) {
		var logEntry = {
			message: message,
			type: errorType,
		};
		log(logEntry);
	},
};

function log(entry) {
	entry.host = hostInfo.get();
	entry.timestamp = new Date();

	if (exchange) {
{'fraction_non_alphanumeric': 0.14676889375684557, 'fraction_numerical': 0.0, 'mean_word_length': 3.858156028368794, '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': '1098811', 'n_tokens_mistral': 1001, 'n_tokens_neox': 871, 'n_words': 220}