<commit_before>/* eslint-disable no-console */
import {isNode} from "./environment.js";
import Timer from "./Timer.js";

const Logger = class {
	constructor(options){
		this.options = {
			nameSeparator: "/",
			console: true,
			consoleErrorPrinter: function(e){
				console.log(e);
			}
		};
		this.reset(options);
	}

	reset(options){
		let result = this.getResults();
		this.options = Object.assign({}, this.options, options);
		this._console = !!this.options.console;
		this._idSeed = 0;
		this._unexpected = false;
		this._totalCount = 0;
		this._passCount = 0;
		this._failCount = 0;
		this._scaffoldFailCount = 0;
		this._results = [];
		this._logs = {};
		return result;
	}

	updateOptions(options){
		this.options = Object.assign({}, this.options, options);
		this._console = !!this.options.console;
	}

	getResults(){
		return {
			unexpected: this._unexpected,
			totalCount: this._totalCount,
			passCount: this._passCount,
			failCount: this._failCount,
			scaffoldFailCount: this._scaffoldFailCount,
			results: this._results,
			logs: this._logs
		};
	}

	get totalCount(){
		return this._totalCount;
	}

	get passCount(){
		return this._passCount;
	}

	get failCount(){
		return this._failCount;
	}

	get scaffoldFailCount(){
		return this._scaffoldFailCount;
	}

	get unexpected(){
		return this._unexpected;
	}

	get results(){
		return this._results;
	}

	get logs(){
		return this._logs;
	}

	getLog(id){
		return this._logs[id];
	}

	getName(context, node, testId){
		return context.map(node => node.id).join(this.options.nameSeparator) +
			(node ? this.options.nameSeparator + node.id : "") +
			(testId ? this.options.nameSeparator + testId : "");
	}

	getNameById(loggerId){
		return this._results[loggerId][0];
	}

	getScaffoldName(context, node){
		let name = [];
		for(let i = 0, end = context.length; i < end; i++){
			name.push(context[i].id);
			if(context[i] === node) break;
		}
		return name.join(this.options.nameSeparator);
	}

	startTest(context){
		this._totalCount++;
		let id = ++(this._idSeed);
		this._results[id] = [this.getName(context), (new Date()).getTime(), new Timer()];
		return id;
	}

	passTest(id){
		this._passCount++;
		let result = this._results[id];
		result[2] = result[2].time;
		if(this._console){
			console.log("PASS[" + result[0] + "]");
		}
	}

	failTest(id, error){
		this._failCount++;
		let result = this._results[id];
		result[2] = false;
		result[3] = error;
		if(this._console){
			console.log("FAIL[" + result[0] + "]");
			this.options.consoleErrorPrinter(error);
		}
	}

	excludeTest(context){
		if(this.options.logExcludes){
			let name = this.getName(context);
			this.log("EXCLUDED", 0, [name]);<commit_msg>rfe: format log output so it can be sent back from a remote browser<commit_after>/* eslint-disable no-console */
import {isNode} from "./environment.js";
import Timer from "./Timer.js";

const Logger = class {
	constructor(options){
		this.options = {
			nameSeparator: "/",
			console: true,
			consoleErrorPrinter: function(e){
				console.log(e);
			}
		};
		this.reset(options);
	}

	reset(options){
		let result = this.getResults();
		this.options = Object.assign({}, this.options, options);
		this._console = !!this.options.console;
		this._idSeed = 0;
		this._unexpected = false;
		this._totalCount = 0;
		this._passCount = 0;
		this._failCount = 0;
		this._scaffoldFailCount = 0;
		this._results = [];
		this._logs = {};
		return result;
	}

	updateOptions(options){
		this.options = Object.assign({}, this.options, options);
		this._console = !!this.options.console;
	}

	getResults(){
		return {
			unexpected: this._unexpected,
			totalCount: this._totalCount,
			passCount: this._passCount,
			failCount: this._failCount,
			scaffoldFailCount: this._scaffoldFailCount,
			results: this._results,
			logs: this._logs
		};
	}

	get totalCount(){
		return this._totalCount;
	}

	get passCount(){
		return this._passCount;
	}

	get failCount(){
		return this._failCount;
	}

	get scaffoldFailCount(){
		return this._scaffoldFailCount;
	}

	get unexpected(){
		return this._unexpected;
	}

	get results(){
		return this._results;
	}

	get logs(){
		return this._logs;
	}

	getLog(id){
		return this._logs[id];
	}

	getName(context, node, testId){
		return context.map(node => node.id).join(this.options.nameSeparator) +
			(node ? this.options.nameSeparator + node.id : "") +
			(testId ? this.options.nameSeparator + testId : "");
	}

	getNameById(loggerId){
		return this._results[loggerId][0];
	}

	getScaffoldName(context, node){
		let name = [];
		for(let i = 0, end = context.length; i < end; i++){
			name.push(context[i].id);
			if(context[i] === node) break;
		}
		return name.join(this.options.nameSeparator);
	}

	startTest(context){
		this._totalCount++;
		let id = ++(this._idSeed);
		this._results[id] = [this.getName(context), (new Date()).getTime(), new Timer()];
		return id;
	}

	passTest(id){
		this._passCount++;
		let result = this._results[id];
		result[2] = result[2].time;
		if(this._console){
			console.log("PASS[" + result[0] + "]");
		}
	}

	failTest(id, error){
		this._failCount++;
		let result = this._results[id];
		result[2] = false;
		result[3] = [error.message, ...(error.stack.split("\n"))];
		if(this._console){
			console.log("FAIL[" + result[0] + "]");
			this.options.consoleErrorPrinter(error);
		}
	}

	excludeTest(context){
		if(this.options.logExcludes){
			let name = this.getName(context);
			this.log("EXCLUDED", 0, [name]);
{'fraction_non_alphanumeric': 0.1664225558403515, 'fraction_numerical': 0.005126327352618088, 'mean_word_length': 3.7670157068062826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '174522', 'n_tokens_mistral': 2156, 'n_tokens_neox': 1921, 'n_words': 375}