<commit_before>'use strict'
const winston = require('winston');
const rabbitChatter = require('rabbit-chatter');

class LevelHelper{
	constructor(){
		this.levels = {
			'error': 1,
			'warn': 2,
			'info': 3,
			'verbose': 4,
			'debug': 5,
			'silly': 6
		}
	}

	isLevelFulfilled(level, minimumLevel){
		const levels = this.levels;

		if(!levels[level])
			return false;

		const levelPriority = levels[level];
		const minimumLevelPriority = levels[minimumLevel];

		return levelPriority <= minimumLevelPriority;
	}
}

class WinstonInstantRabbitMq{
	constructor(options){
		this.name = 'winstonFastRabbitMq';

		if(!options)
			options = {};

		this.level = options.level || 'info';
        this.formatter = options.formatter || function(level, meta, message)
        {
            return JSON.stringify({ level: level, meta: meta, message: message  });
        };
				
		const rabbitOptions = {
			appId: options.appId || options.applicationId,
			silent: options.silent,
			exchangeType: options.exchangeType,
			exchangeName: options.exchangeName || 'winston-log',
			durable: options.durable,
			protocol: options.protocol || 'amqp',
			username: options.username || 'guest',
			password: options.password || '<PASSWORD>',
			host: options.host || 'localhost',
			virtualHost: options.virtualHost ? options.virtualHost : '',
			port: options.port || 5672,
			routingKey: options.routingKey || '',
			handleError: options.handleError
		};
		
		this._rabbit = rabbitChatter.rabbit(rabbitOptions);

		this._levelHelper = new LevelHelper();
	}

	log(level, msg, meta, callback){
		let t = this;

		const levelHelper = new LevelHelper();

		if(!t._levelHelper.isLevelFulfilled(level, t.level))
			return;

		msg = t.formatter(level, meta, msg);

		//rabbit chat here
		t._rabbit.chat(msg);
	}

	//Winston will fail without this
	on(level, callback){}
}

<commit_msg>Refactor to comply with winston formatter function signature.<commit_after>'use strict'
const winston = require('winston');
const rabbitChatter = require('rabbit-chatter');

class LevelHelper{
	constructor(){
		this.levels = {
			'error': 1,
			'warn': 2,
			'info': 3,
			'verbose': 4,
			'debug': 5,
			'silly': 6
		}
	}

	isLevelFulfilled(level, minimumLevel){
		const levels = this.levels;

		if(!levels[level])
			return false;

		const levelPriority = levels[level];
		const minimumLevelPriority = levels[minimumLevel];

		return levelPriority <= minimumLevelPriority;
	}
}

class WinstonInstantRabbitMq{
	constructor(options){
		this.name = 'winstonFastRabbitMq';

		if(!options)
			options = {};

		this.level = options.level || 'info';
        this.formatter = options.formatter || function (options)
        {
            return JSON.stringify({ level: options.level, meta: options.meta, message: options.message });
        };
				
		const rabbitOptions = {
			appId: options.appId || options.applicationId,
			silent: options.silent,
			exchangeType: options.exchangeType,
			exchangeName: options.exchangeName || 'winston-log',
			durable: options.durable,
			protocol: options.protocol || 'amqp',
			username: options.username || 'guest',
			password: options.password || '<PASSWORD>',
			host: options.host || 'localhost',
			virtualHost: options.virtualHost ? options.virtualHost : '',
			port: options.port || 5672,
			routingKey: options.routingKey || '',
			handleError: options.handleError
		};
		
		this._rabbit = rabbitChatter.rabbit(rabbitOptions);

		this._levelHelper = new LevelHelper();
	}

	log(level, msg, meta, callback){
		let t = this;

		const levelHelper = new LevelHelper();

		if(!t._levelHelper.isLevelFulfilled(level, t.level))
			return;

		const output = {
			level: level,
			message: msg,
			meta: meta,
		}

		msg = t.formatter(output);

		//rabbit chat here
		t._rabbit.chat(msg);

		if (callback)
			callback(null, true);
	}

	//Winston will fail without this
	on(level, callback){}
}


{'fraction_non_alphanumeric': 0.13673678809645973, 'fraction_numerical': 0.00513083632632119, 'mean_word_length': 3.6919374247894106, 'pattern_counts': {'":': 0, '<': 7, '<?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': '788798', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1205, 'n_words': 284}