<commit_before>var winston = require('winston')
,   common  = require('./common')
,   stats   = require('./stats')

// These need to be shared across triton and corvair.
var loggers = (global._TRITON_LOGGERS || (global._TRITON_LOGGERS = {}));

if (!Object.keys(loggers).length)
	for (var group in common.config)
		loggers[group] = new winston.Container({});

var getLoggerForConfig = function(group, opts){
	var config = common.config[group];

	// The `loggers` collection's `get` method auto-adds on miss, and
	// returns existing on hit.
	var logger = loggers[group].get(opts.name, {
		console: {
			level     : config.baseLevel,
			timestamp : false,  // TODO: Want this in production.
		}
		// TODO: Email transport for high-level logs in production.
	});

	// Need to be able to refresh this.
	(logger.updateColorize = function(){
		logger.transports.console.label = colorizeName(opts);
		logger.transports.console.colorize = COLORIZE_TRITON_LOG_OUTPUT;
	})();

	logger.setLevels(config.levels);

	winston.addColors(config.colors);

	return logger;
}

var colorizeName = function(opts){

	// Only colorize if we're attached to a terminal.
	if (!COLORIZE_TRITON_LOG_OUTPUT)
		return opts.name;

	return `\x1B[38;5;${opts.color.server}m${opts.name}\x1B[0m`;
}

var getLogger = stats.makeGetLogger(getLoggerForConfig);

var setLevel = function(group, level){

	// Update level for any future loggers.
	common.config[group].baseLevel = level;

	// Also need to reconfigure any loggers that are alredy set up.
	for (var logger in loggers[group].loggers)
		loggers[group].loggers[logger].transports.console.level = level;
}

var setColorize = function(bool){

	global.COLORIZE_TRITON_LOG_OUTPUT = bool;

	Object.keys(common.config).forEach(group => {

		// Update any loggers that are alredy set up.
		for (var logger in loggers[group].loggers)
			loggers[group].loggers[logger].updateColorize();

	});
}

// Default is only if we're directly attached to a terminal.
// Can be overridden (This `setColorize` function is exported).
setColorize(process.stdout.isTTY);

module.exports = { getLogger, setLevel, setColorize };<commit_msg>Use file transport and kill winston containers<commit_after>var winston = require('winston')
,   common  = require('./common')
,   stats   = require('./stats')

// These need to be shared across triton and corvair.
var loggers = (global._TRITON_LOGGERS || (global._TRITON_LOGGERS = {}));

if (!Object.keys(loggers).length)
	for (var group in common.config)
		loggers[group] = {};

var makeLogger = function(group, opts){
	var config = common.config[group];

	var fileTransport = new (winston.transports.File)({
		name      : 'file',
		level     : config.baseLevel,
		stream    : process.stdout,
		json      : false,
		timestamp : false,  // TODO: Want this in production.
	});

	var logger = loggers[group][opts.name] = new (winston.Logger)({
		transports: [
			fileTransport,
		]
	});

	// Need to be able to refresh this.
	(logger.updateColorize = function(){
		logger.transports.file.label = colorizeName(opts);
		logger.transports.file.colorize = COLORIZE_TRITON_LOG_OUTPUT;
	})();

	logger.setLevels(config.levels);

	winston.addColors(config.colors);

	return logger;
}

var getLoggerForConfig = function(group, opts){
	return loggers[group][opts.name] || (
		loggers[group][opts.name] = makeLogger(group, opts)
	);
}

var colorizeName = function(opts){

	// Only colorize if we're attached to a terminal.
	if (!COLORIZE_TRITON_LOG_OUTPUT)
		return opts.name;

	return `\x1B[38;5;${opts.color.server}m${opts.name}\x1B[0m`;
}

var getLogger = stats.makeGetLogger(getLoggerForConfig);

var setLevel = function(group, level){

	// Update level for any future loggers.
	common.config[group].baseLevel = level;

	// Also need to reconfigure any loggers that are alredy set up.
	for (var logger in loggers[group])
		loggers[group][logger].transports.file.level = level;
}

var setColorize = function(bool){

	global.COLORIZE_TRITON_LOG_OUTPUT = bool;

	Object.keys(common.config).forEach(group => {

		// Update any loggers that are alredy set up.
		for (var logger in loggers[group])
			loggers[group][logger].updateColorize();

	});
}

// Default is only if we're directly attached to a terminal.
// Can be overridden (This `setColorize` function is exported).
setColorize(process.stdout.isTTY);

module.exports = { getLogger, setLevel, setColorize };
{'fraction_non_alphanumeric': 0.13204104903078678, 'fraction_numerical': 0.0027366020524515395, 'mean_word_length': 4.252694610778443, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7020624', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1436, 'n_words': 367}