<commit_before>
/**
 * logging.js:	Simple logger
 *
 * (c) 2013, dotfold
 */
var r = require('./../util/replacetokens')

//
// ### function _loggerImpl name
// #### @name {String} Name of this logger instance
// Logger object
// 
var _loggerImpl = function(name) {
	
	//
	// Name of this logger instance
	//
	this.name = name;

	//
	// Message token string
	// 
	_logTemplate = '{messageColor}{date} {level} - {nameColor}{name}{messageColor} - {message}{noColor}';

	//
	// Default token replace data
	// 
	var defaultData = {
		messageColor: '\033' + String.fromCharCode(27) + '[36m',
		nameColor: '\033' + String.fromCharCode(27) + '[33m',
		noColor: '\033' + String.fromCharCode(27) + '[39m'
	}

	//
	// Object `map` of colors to use for each LogLevel
	// 
	var colorsByLogLevel = {
		NONE	: '0',
		DEBUG	: '\033' + String.fromCharCode(27) + '[39m',	// white
		INFO	: '\033' + String.fromCharCode(27) + '[36m',	// cyan
		WARN	: '\033' + String.fromCharCode(27) + '[35m',	// magenta
		ERROR	: '\033' + String.fromCharCode(27) + '[31m'		// red
	}

	//
	// ### function _replaceTokens data
	// #### @data {Object} key value pairs to replace
	// Merges the supplied data object with defaults
	// 
	_replaceTokens = function(data) {

		for (var field in data) {
			defaultData[field] = data[field];
		}

		return r.replace(_logTemplate, defaultData)
	}

	//
	// ### function _formateDate date
	// #### @date Date object
	// Formats the supplied Date object to a human readable string for output.
	_formatDate = function(date) {

		return date.toDateString() + ' '
			+ date.getHours()+ ':'
			+ date.getMinutes() + ':'
			+ date.getSeconds();
	}

	//
	// ### function _log level, msg
	// #### @level {String} LogLevel for this message
	// #### @msg {String} The message to log to stdout
	// Formats a message with date, name and message and
	// outputs the result to the console
	// 
	_log = function(level, msg) {
		var date = new Date();
		var replaced = _replaceTokens({
			messageColor: colorsByLogLevel[level],
			date: _formatDate(date),
			level: level,
			name: this.name,
			message: msg
		})

		console.log(replaced);
	}
}

_loggerImpl.prototype = {

	//
	// ### function debug msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs a DEBUG level message to the console.
	// 
	debug: function(msg, args) {
		_log.call(this, 'DEBUG', msg);
	},

	//
	// ### function info msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs an INFO level message to the console.
	// 
	info: function(msg, args) {
		_log.call(this, 'INFO', msg);
	},

	//
	// ### function warn msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs a WARN level message to the console.
	// 
	warn: function(msg, args) {
		_log.call(this, 'WARN', msg);
	},

	//
	// ### function error msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs an ERROR level message to the console.
	// 
	error: function(msg, args) {
		_log.call(this, 'ERROR', msg);
	}

}

//
// ### function getLogger name
// #### @name {String} the name of this logger instance
// Creates a new logger object with the given name.
// The name is used in the output, the following template is used:
// <Date> <Level> - <name> - <message>
// 
exports.getLogger = function(name) {
	return new _loggerImpl(name);
}
<commit_msg>[api] add logger level enum<commit_after>
/**
 * logging.js:	Simple logger
 *
 * (c) 2013, dotfold
 */
var r = require('./../util/replacetokens')

// TODO: provide logger factory
// TODO: provide alt loggers, not just console

//
// ### function _loggerImpl name
// #### @name {String} Name of this logger instance
// Logger object
// 
var _loggerImpl = function(name) {
	
	//
	// Name of this logger instance
	//
	this.name = name;

	//
	// Message token string
	// 
	_logTemplate = '{messageColor}{date} {level} - {nameColor}{name}{messageColor} - {message}{noColor}';

	//
	// Default token replace data
	// 
	var defaultData = {
		messageColor: '\033' + String.fromCharCode(27) + '[36m',
		nameColor: '\033' + String.fromCharCode(27) + '[33m',
		noColor: '\033' + String.fromCharCode(27) + '[39m'
	}

	//
	// Object `map` of colors to use for each LogLevel
	// 
	var colorsByLogLevel = {
		NONE	: '0',
		DEBUG	: '\033' + String.fromCharCode(27) + '[39m',	// white
		INFO	: '\033' + String.fromCharCode(27) + '[36m',	// cyan
		WARN	: '\033' + String.fromCharCode(27) + '[35m',	// magenta
		ERROR	: '\033' + String.fromCharCode(27) + '[31m'		// red
	}

	//
	// ### function _replaceTokens data
	// #### @data {Object} key value pairs to replace
	// Merges the supplied data object with defaults
	// 
	_replaceTokens = function(data) {

		for (var field in data) {
			defaultData[field] = data[field];
		}

		return r.replace(_logTemplate, defaultData)
	}

	//
	// ### function _formateDate date
	// #### @date Date object
	// Formats the supplied Date object to a human readable string for output.
	_formatDate = function(date) {

		return date.toDateString() + ' '
			+ date.getHours()+ ':'
			+ date.getMinutes() + ':'
			+ date.getSeconds();
	}

	//
	// ### function _log level, msg
	// #### @level {String} LogLevel for this message
	// #### @msg {String} The message to log to stdout
	// Formats a message with date, name and message and
	// outputs the result to the console
	// 
	_log = function(level, msg) {
		var date = new Date();
		var replaced = _replaceTokens({
			messageColor: colorsByLogLevel[level],
			date: _formatDate(date),
			level: level,
			name: this.name,
			message: msg
		})

		// for like {0}, {1} etc in args
		var tokenized = '';
		// regex to array
		// run through the array, and the args.slice
		// and match them up
		// any remaining ones just spit them out the end

		console.log(replaced);
	}
}

_loggerImpl.prototype = {

	//
	// ### function debug msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs a DEBUG level message to the console.
	// 
	debug: function(msg, args) {
		_log.call(this, 'DEBUG', msg);
	},

	//
	// ### function info msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs an INFO level message to the console.
	// 
	info: function(msg, args) {
		_log.call(this, 'INFO', msg);
	},

	//
	// ### function warn msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs a WARN level message to the console.
	// 
	warn: function(msg, args) {
		_log.call(this, 'WARN', msg);
	},

	//
	// ### function error msg, args
	// #### @msg {String} message to log
	// #### @args {Array} any arguments to append to log
	// Outputs an ERROR level message to the console.
	// 
	error: function(msg, args) {
		_log.call(this, 'ERROR', msg);
	}

}

//
// ### function getLogger name
// #### @name {String} the name of this logger instance
// Creates a new logger object with the given name.
// The name is used in the output, the following template is used:
// <Date> <Level> - <name> - <message>
// 
exports.getLogger = function(name) {
	return new _loggerImpl(name);
}

//
// threshold for messages
//
exports.setLogLevel = function(level) {

}

exports.LEVEL = {
	NONE:	'none',
	DEBUG: 	'debug',
	INFO: 	'info',
	WARN:	'warn',
	ERROR:	'error'
}

{'fraction_non_alphanumeric': 0.16867631296891747, 'fraction_numerical': 0.014737406216505895, 'mean_word_length': 2.898172323759791, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6371213', 'n_tokens_mistral': 2710, 'n_tokens_neox': 2557, 'n_words': 793}