<commit_before>var strftime = require('strftime').utc();
var fs = require('fs');
require('colors');

module.exports = function (config) {
	config = config || {};
	var exports = {};

	config.levels = config.levels || {
		"trace": 0,
		"debug": 1,
		"log": 2,
		"info": 3,
		"warn": 4,
		"error": 5,
		"fatal": 6
	}

	config.filename = config.filename || __dirname + '/logs.log';

	config.errorLevel = config.errorLevel || "log";

	var log_file = fs.createWriteStream(config.filename, {flags: 'a'});

	exports.setLevel = function (errorLevel) {
		config.errorLevel = errorLevel;
	}

	Object.keys(config.levels).forEach(function (name) {
		function log(caption, data) {
			var log = {
				"level": name,
				"message": caption,
				"timestamp": strftime('%F %T', new Date())
			}

			data && (log["data"] = data);

			if (config.levels[config.errorLevel] <= config.levels[log.level]) {
				log_file.write(JSON.stringify(log) + '\n');
			}
			if (config.echo && config.levels[config.echo] <= config.levels[log.level]) {
				try {
					console.log(log.level.bgYellow.black, log.timestamp.grey, log.message, log.data ? log.data : '');
				}catch (e){
					console.log(e)
				}
			}
		}

		exports[name] = log;
	})

	return exports;<commit_msg>Beautifying code.<commit_after>var strftime = require("strftime").utc();
var fs = require("fs");
require("colors");

module.exports = function (config) {
	config = config || {};
	var exports = {};

	config.levels = config.levels || {
		"trace": 0,
		"debug": 1,
		"log": 2,
		"info": 3,
		"warn": 4,
		"error": 5,
		"fatal": 6
	}

	config.filename = config.filename || __dirname + "/logs.log";

	config.errorLevel = config.errorLevel || "log";

	var log_file = fs.createWriteStream(config.filename, { flags: "a" });

	exports.setLevel = function (errorLevel) {
		config.errorLevel = errorLevel;
	}

	Object.keys(config.levels).forEach(function (name) {
		function log(caption, data) {
			var log = {
				"level": name,
				"message": caption,
				"timestamp": strftime("%F %T", new Date())
			}

			data && (log["data"] = data);

			if (config.levels[config.errorLevel] <= config.levels[log.level]) {
				log_file.write(JSON.stringify(log) + "\n");
			}
			if (config.echo && config.levels[config.echo] <= config.levels[log.level]) {
				try {
					console.log(log.level.bgYellow.black, log.timestamp.grey, log.message, log.data ? log.data : "");
				}catch (e){
					console.log(e)
				}
			}
		}

		exports[name] = log;
	})

	return exports;
{'fraction_non_alphanumeric': 0.1907258064516129, 'fraction_numerical': 0.00564516129032258, 'mean_word_length': 3.454219030520646, 'pattern_counts': {'":': 20, '<': 7, '<?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': '5639578', 'n_tokens_mistral': 1032, 'n_tokens_neox': 863, 'n_words': 176}