<commit_before>package me.coley.recaf.util;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.core.FileAppender;
import me.coley.recaf.Recaf;
import me.coley.recaf.util.struct.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Matcher;

/**
 * Proxy to intercept tinylog logging.
 *
 * @author Matt
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public class Log {
	public static final String APP_LOGGER = "recaf-logger";
	public static final String FILE_LOGGER = "recaf-file-logger";
	public static final Logger appLogger = LoggerFactory.getLogger(APP_LOGGER);
	public static final Logger fileLogger;
	/**
	 * Set of consumers that are fed trace-level messages.
	 */
	public static final Set<Consumer<String>> traceConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed debug-level messages.
	 */
	public static final Set<Consumer<String>> debugConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed info-level messages.
	 */
	public static final Set<Consumer<String>> infoConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed warn-level messages.
	 */
	public static final Set<Consumer<String>> warnConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed error-level messages.
	 */
	public static final Set<Consumer<Pair<String, Throwable>>> errorConsumers = new HashSet<>();

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void trace(String msg, Object... args) {
		appLogger.trace(msg, args);
		fileLogger.trace(msg, args);
		traceConsumers.forEach(c -> c.accept(compile(msg, args)));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void debug(String msg, Object... args) {
		appLogger.debug(msg, args);
		fileLogger.debug(msg, args);
		debugConsumers.forEach(c -> c.accept(compile(msg, args)));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void info(String msg, Object... args) {
		appLogger.info(msg, args);
		fileLogger.info(msg, args);
		infoConsumers.forEach(c -> c.accept(compile(msg, args)));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void warn(String msg, Object... args) {
		appLogger.warn(msg, args);
		fileLogger.warn(msg, args);
		warnConsumers.forEach(c -> c.accept(compile(msg, args)));
	}

	/**
	 * @param t
	 * 		Exception to print.
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void warn(Throwable t, String msg, Object... args) {
		String msgCmp = compile(msg,args);
		appLogger.warn(msgCmp, t);
		fileLogger.warn(msgCmp, t);
		warnConsumers.forEach(c -> c.accept(msgCmp));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void error(String msg, Object... args) {
		error(null, msg, args);
	}

	/**
	 * @param t
	 * 		Exception to print.
	 * @param msg<commit_msg>fix: some log messages not being reformatted correctly<commit_after>package me.coley.recaf.util;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.core.FileAppender;
import me.coley.recaf.Recaf;
import me.coley.recaf.util.struct.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Matcher;

/**
 * Proxy to intercept tinylog logging.
 *
 * @author Matt
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public class Log {
	public static final String APP_LOGGER = "recaf-logger";
	public static final String FILE_LOGGER = "recaf-file-logger";
	public static final Logger appLogger = LoggerFactory.getLogger(APP_LOGGER);
	public static final Logger fileLogger;
	/**
	 * Set of consumers that are fed trace-level messages.
	 */
	public static final Set<Consumer<String>> traceConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed debug-level messages.
	 */
	public static final Set<Consumer<String>> debugConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed info-level messages.
	 */
	public static final Set<Consumer<String>> infoConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed warn-level messages.
	 */
	public static final Set<Consumer<String>> warnConsumers = new HashSet<>();
	/**
	 * Set of consumers that are fed error-level messages.
	 */
	public static final Set<Consumer<Pair<String, Throwable>>> errorConsumers = new HashSet<>();

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void trace(String msg, Object... args) {
		String msgCmp = compile(msg,args);
		appLogger.trace(msgCmp);
		fileLogger.trace(msgCmp);
		traceConsumers.forEach(c -> c.accept(msgCmp));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void debug(String msg, Object... args) {
		String msgCmp = compile(msg,args);
		appLogger.debug(msgCmp);
		fileLogger.debug(msgCmp);
		debugConsumers.forEach(c -> c.accept(msgCmp));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void info(String msg, Object... args) {
		String msgCmp = compile(msg,args);
		appLogger.info(msgCmp);
		fileLogger.info(msgCmp);
		infoConsumers.forEach(c -> c.accept(msgCmp));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void warn(String msg, Object... args) {
		String msgCmp = compile(msg,args);
		appLogger.warn(msgCmp);
		fileLogger.warn(msgCmp);
		warnConsumers.forEach(c -> c.accept(msgCmp));
	}

	/**
	 * @param t
	 * 		Exception to print.
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void warn(Throwable t, String msg, Object... args) {
		String msgCmp = compile(msg,args);
		appLogger.warn(msgCmp, t);
		fileLogger.warn(msgCmp, t);
		warnConsumers.forEach(c -> c.accept(msgCmp));
	}

	/**
	 * @param msg
	 * 		Message format.
	 * @param args
	 * 		Message arguments.
	 */
	public static void error(String msg, Object... args) {
		error(null, msg, args);
	}

	/**
	 * @param t
	 * 		Exception to print.
	 * @param msg
{'fraction_non_alphanumeric': 0.13581712928603235, 'fraction_numerical': 0.0005937360843105239, 'mean_word_length': 3.6087551299589604, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 45, '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': '3821555', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2173, 'n_words': 580}