<commit_before>/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2014 <NAME>. <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
var path = require("path");
var cache = {}, root = null;

/*
 * Logging.js is a lightweight logging library for Node.js based on the 
 *	java.util.logging package.
 */
function logging() {}

/*
 * Return the root {@link logging.Logger} instance.
 *
 * @return The root {@link logging.Logger} instance. 
 */
logging.root = function() {
	return root || (root = new logging.Logger("root"));
};

/* 
 * Return a new {@link Logger} instance if it doesn't exist already,
 *	return the one from the cache otherwise.
 *
 * @param module The module to get the {@link Logger} instance of.
 * @return The {@link Logger} instance.
 */
logging.get = function(module) {
	if (cache.hasOwnProperty(module))
		return cache[module];
	return cache[module] = new logging.Logger(module);
};

/*
 * A {@link Logger} object is used to log messages for a specific system or 
 *	application module.
 *
 * @param module The module of this {@link Logger} instance.
 */
logging.Logger = function(module) {
	var instance = this;
	var levels = {};
	Object.defineProperty(this, "levels", {
		get : function() {
			return levels; 
		},
		set : function(value) {
			for (var key in levels) {
				instance[levels[key].name.toLowerCase()] = null;
			}
			for (var key in value) {
				if (value[key].ignore)
					continue;
				instance[value[key].name.toLowerCase()] = (function(level) {
					return function() {
						instance.log.apply(this, [level].concat(Array.prototype.slice.call(arguments)));
					};
				})(value[key]);
			}
			levels = value;
		}
	});
	this.levels = logging.Levels;
	this.level = this.levels.INFO;
	this.filter = function(record) { return true; };
	this.handlers = [];
	
	if (module == null || typeof module !== 'object')
		return;
	
	var name = (module == "root") ? "root" : path.basename(module.filename);
	var parent = (module == "root") ? "root" : 
		(module.parent == null ? logging.root() : logging.get(module.parent))
	Object.defineProperty(this, "name", {value : name, writable : false});
	Object.defineProperty(this, "module", {value : module, writable : false});
	Object.defineProperty(this, "parent", {value : parent, writable : false});
	return this;
};

/*
 * Determines whether the given level is high enough to be logged by this 
 *	{@link Logger} instance.
 *
 * @param level The level to check.
 * @return <code>true</code> if the given level is high enough to be logged
 *	by this {@link Logger} instance, <code>false</code> otherwie.
 */
logging.Logger.prototype.isLoggable = function(level) {
	return level.value >= this.level.value;
};

/*
 * Logs the given message with the given level.
 *
 * @param level The level of this message.
 * @param message The message to log.
 */
logging.Logger.prototype.log = function(level, message) {
	var record = new logging.Record(level, message);
	record.loggerName = this.name;
	record.parameters = arguments;
	record.parameters =  Array.prototype.slice.call(record.parameters).slice(2);
	
	if (message instanceof Error) {
		record.message = null;
		record.thrown = message;
	}
	
	this.logr(record);
};

/*
 * Logs the given {@link logging.Record} instance.
 *
 * @param record The {@link logging.Record} instance to log.
 */
logging.Logger.prototype.logr = function(record) {
	if (!this.isLoggable(record.level))
		return;
	if (this.filter && !this.filter(record))
		return;
	this.handlers.forEach(function(handler) {
		if (handler.isLoggable(record))
			handler(record);
	});
};

/*
 * {@link Record} objects are used to pass logging requests between the logging 
 *	framework and individual log handlers.
 * When a {@link Record} is passed into the logging framework it logically 
 * 	belongs to the framework and should no longer be used or updated by the 
 *	client application.
 *<commit_msg>Add parent loggers<commit_after>/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2014 <NAME>. <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
var path = require("path");
var cache = {}, root = null;

/*
 * Logging.js is a lightweight logging library for Node.js based on the 
 *	java.util.logging package.
 */
function logging() {}

/*
 * Return the root {@link logging.Logger} instance.
 *
 * @return The root {@link logging.Logger} instance. 
 */
logging.root = function() {
	return root || (root = new logging.Logger("root"));
};

/* 
 * Return a new {@link Logger} instance if it doesn't exist already,
 *	return the one from the cache otherwise.
 *
 * @param module The module to get the {@link Logger} instance of.
 * @return The {@link Logger} instance.
 */
logging.get = function(module) {
	if (cache.hasOwnProperty(module))
		return cache[module];
	return cache[module] = new logging.Logger(module);
};

/*
 * A {@link Logger} object is used to log messages for a specific system or 
 *	application module.
 *
 * @param module The module of this {@link Logger} instance.
 */
logging.Logger = function(module) {
	var instance = this;
	var levels = {};
	Object.defineProperty(this, "levels", {
		get : function() {
			return levels; 
		},
		set : function(value) {
			for (var key in levels) {
				instance[levels[key].name.toLowerCase()] = null;
			}
			for (var key in value) {
				if (value[key].ignore)
					continue;
				instance[value[key].name.toLowerCase()] = (function(level) {
					return function() {
						instance.log.apply(this, [level].concat(Array.prototype.slice.call(arguments)));
					};
				})(value[key]);
			}
			levels = value;
		}
	});
	this.levels = logging.Levels;
	this.level = this.levels.INFO;
	this.filter = function(record) { return true; };
	this.handlers = [];
	
	if (module == null || typeof module !== 'object')
		return;
	
	var name = (module == "root") ? "root" : path.basename(module.filename);
	var parent = (module == "root") ? "root" : 
		(module.parent == null ? logging.root() : logging.get(module.parent))
	Object.defineProperty(this, "name", {value : name, writable : false});
	Object.defineProperty(this, "module", {value : module, writable : false});
	Object.defineProperty(this, "parent", {value : parent, writable : false});
	return this;
};

/*
 * Determines whether the given level is high enough to be logged by this 
 *	{@link Logger} instance.
 *
 * @param level The level to check.
 * @return <code>true</code> if the given level is high enough to be logged
 *	by this {@link Logger} instance, <code>false</code> otherwie.
 */
logging.Logger.prototype.isLoggable = function(level) {
	return level.value >= this.level.value;
};

/*
 * Logs the given message with the given level.
 *
 * @param level The level of this message.
 * @param message The message to log.
 */
logging.Logger.prototype.log = function(level, message) {
	var record = new logging.Record(level, message);
	record.loggerName = this.name;
	record.parameters = arguments;
	record.parameters =  Array.prototype.slice.call(record.parameters).slice(2);
	
	if (message instanceof Error) {
		record.message = null;
		record.thrown = message;
	}
	
	this.logr(record);
};

/*
 * Logs the given {@link logging.Record} instance.
 *
 * @param record The {@link logging.Record} instance to log.
 */
logging.Logger.prototype.logr = function(record) {
	if (!this.isLoggable(record.level))
		return;
	if (this.filter && !this.filter(record))
		return;
	this.handlers.forEach(function(handler) {
		if (handler.isLoggable(record))
			handler(record);
	});
	if (this.parent)
		this.parent.logr(record);
};

/*
 * {@link Record} objects are used to pass logging requests between the logging 
 *	framework and individual log handlers.
 * When a {@link Record} is passed into the logging framework it logically 
 * 	belongs to the framework and should no longer be used or updated by the 
 *	client application.
 *
{'fraction_non_alphanumeric': 0.12291181532854105, 'fraction_numerical': 0.0010124531740407007, 'mean_word_length': 3.8708086785009863, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '1821289', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2828, 'n_words': 1073}