<commit_before>package ingraph.logger

import java.util.ArrayList
import java.util.List
import java.util.logging.Level
import java.util.logging.LogRecord
import java.util.logging.Logger
import java.util.logging.ConsoleHandler

/**
 * This is a wrapper over java.util.logging.Logger
 *
 * The main difference is that IngraphLogger instances are not provided by any factory.
 * Under the hood, it forwards logging messages to a java.util.logging.Logger
 * provided upon object instantiation by name or by passing the Logger instance itself.
 */
class IngraphLogger {
	String name
	Logger logger

	List<LogRecord> records = new ArrayList<LogRecord>

	/**
	 * Constructs a new IngraphLogger. Use the loggerName passed in to obtain
	 * the java.util.logging.Logger to be used.
	 * 
	 * This constructor also ensures that messages are output the the console.
	 */
	new(String loggerName) {
		this.name = loggerName
		this.logger = Logger.getLogger(name)

		/*
		 *  For multiple runs in a single JVM, we should not add more than 1 ConsoleHandler
		 */
		var seenConsoleHandler = false;
		for (h: this.logger.handlers) {
			if (h instanceof ConsoleHandler) {
				seenConsoleHandler = true
			}
		}
		if (!seenConsoleHandler) {
			this.logger.addHandler(new ConsoleHandler)
		}
	}

	new(Logger logger) {
		this.name = logger.getName
		this.logger = logger
	}

	def warning(String msg) {
		log(Level.WARNING, msg)
	}

	def warning(String msg, Throwable e) {
		log(Level.WARNING, msg)
		log(Level.WARNING, e)
	}

	def warning(Throwable e) {
		log(Level.WARNING, e)
	}

	def error(String msg) {
		log(Level.SEVERE, msg)
	}

	def error(String msg, Throwable e) {
		log(Level.SEVERE, msg)
		log(Level.SEVERE, e)
	}

	def error(Throwable e) {
		log(Level.SEVERE, e)
	}

	def info(String msg) {
		if (isDebugMode) {
			log(Level.INFO, msg)
		}
	}

	/**
	 * Indicates that the compiler encountered a query part that is not supported,
	 * but should be supported. UnsupportedOperationException is thrown.
	 */
	def unsupported(String msg) {
		error(msg)
		throw new UnsupportedOperationException('''Not supported (yet) «msg»''')
	}

	/**
	 * Indicates an unrecoverable error.
	 *
	 * TODO (to be determined later): Compilation might or might not be aborted.
	 */
	def unrecoverableError(String msg) {
		error(msg)
		throw new RuntimeException('''Unrecoverable error during compilation: «msg»''')
	}

	def log(Level level, String msg) {
		records.add(new LogRecord(level, msg))
		logger.log(level, msg)
	}

	def log(Level level, Throwable e) {
		records.add(new LogRecord(level, e.toString))
		logger.log(level, e.toString)
	}

	def isDebugMode() {
		"1".equals(System.getenv("DEBUG")) || //
		"1".equals(System.getenv("DEBUG_INGRAPH")) || //
		"1".equals(System.getenv("DEBUG_INGRAPH_CYPHER2SEARCH"))
	}

}<commit_msg>Restrict visibility and deprecate debug mode indicator in IngraphLogger<commit_after>package ingraph.logger

import java.util.ArrayList
import java.util.List
import java.util.logging.Level
import java.util.logging.LogRecord
import java.util.logging.Logger
import java.util.logging.ConsoleHandler

/**
 * This is a wrapper over java.util.logging.Logger
 *
 * The main difference is that IngraphLogger instances are not provided by any factory.
 * Under the hood, it forwards logging messages to a java.util.logging.Logger
 * provided upon object instantiation by name or by passing the Logger instance itself.
 */
class IngraphLogger {
	String name
	Logger logger

	List<LogRecord> records = new ArrayList<LogRecord>

	/**
	 * Constructs a new IngraphLogger. Use the loggerName passed in to obtain
	 * the java.util.logging.Logger to be used.
	 * 
	 * This constructor also ensures that messages are output the the console.
	 */
	new(String loggerName) {
		this.name = loggerName
		this.logger = Logger.getLogger(name)

		/*
		 *  For multiple runs in a single JVM, we should not add more than 1 ConsoleHandler
		 */
		var seenConsoleHandler = false;
		for (h: this.logger.handlers) {
			if (h instanceof ConsoleHandler) {
				seenConsoleHandler = true
			}
		}
		if (!seenConsoleHandler) {
			this.logger.addHandler(new ConsoleHandler)
		}
	}

	new(Logger logger) {
		this.name = logger.getName
		this.logger = logger
	}

	def warning(String msg) {
		log(Level.WARNING, msg)
	}

	def warning(String msg, Throwable e) {
		log(Level.WARNING, msg)
		log(Level.WARNING, e)
	}

	def warning(Throwable e) {
		log(Level.WARNING, e)
	}

	def error(String msg) {
		log(Level.SEVERE, msg)
	}

	def error(String msg, Throwable e) {
		log(Level.SEVERE, msg)
		log(Level.SEVERE, e)
	}

	def error(Throwable e) {
		log(Level.SEVERE, e)
	}

	def info(String msg) {
		if (isDebugMode) {
			log(Level.INFO, msg)
		}
	}

	/**
	 * Indicates that the compiler encountered a query part that is not supported,
	 * but should be supported. UnsupportedOperationException is thrown.
	 */
	def unsupported(String msg) {
		error(msg)
		throw new UnsupportedOperationException('''Not supported (yet) «msg»''')
	}

	/**
	 * Indicates an unrecoverable error.
	 *
	 * TODO (to be determined later): Compilation might or might not be aborted.
	 */
	def unrecoverableError(String msg) {
		error(msg)
		throw new RuntimeException('''Unrecoverable error during compilation: «msg»''')
	}

	def log(Level level, String msg) {
		records.add(new LogRecord(level, msg))
		logger.log(level, msg)
	}

	def log(Level level, Throwable e) {
		records.add(new LogRecord(level, e.toString))
		logger.log(level, e.toString)
	}

	/**
	 * FIXME this is a dirty hack to explicitly use debug mode settings from the compiler's environment..
	 */
	@Deprecated
	private def isDebugMode() {
		"1".equals(System.getenv("DEBUG")) || //
		"1".equals(System.getenv("DEBUG_INGRAPH")) || //
		"1".equals(System.getenv("DEBUG_INGRAPH_CYPHER2SEARCH"))
	}

}
{'fraction_non_alphanumeric': 0.10942354159475319, 'fraction_numerical': 0.0017259233690024164, 'mean_word_length': 3.797185430463576, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5400434', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1832, 'n_words': 558}