<commit_before>package net.exodiusmc.blasteroids;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import javafx.application.Platform;
import net.exodiusmc.blasteroids.enums.LogLevel;

/**
 * The Logger class is used to log messages to the console and
 * log file output.
 */
public class Logger {
	private static String filename = "log.txt";
	private static Logger instance;
	private File logfile;
	private BufferedWriter writer;
	
	/**
	 * Returns the associated Logger object
	 * 
	 * @return Logger
	 */
	public static Logger getLogger() {
		if(instance == null) {
			instance = new Logger();
		}
		
		return instance;
	}
	
	@SuppressWarnings("deprecation")
	private Logger() {
		this.logfile = new File(filename);
		
		if(!logfile.exists()) {
			try {
				logfile.createNewFile();
			} catch(IOException e) {
				e.printStackTrace();
			}
		}
		
		try {
			this.writer = new BufferedWriter(new FileWriter(logfile));
		} catch(IOException e) {
			e.printStackTrace();
		}
		
		try {
			Date d = new Date();
			this.writer.write("********** Loading Blasteroids " + Main.getVersion() + " (" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ") **********");
			this.writer.newLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Set the log destination of the logfile output
	 * 
	 * @param name String
	 */
	public static void setLogDestination(String name) {
		filename = name;
	}
	
	/**
	 * Perform a basic log message. Custom LogLevels can be included to alter
	 * the tags inserted before the message
	 * 
	 * @param message String
	 * @param tags LogLevels
	 */
	@SuppressWarnings("deprecation")
	public void log(String message, LogLevel... tags) {
		Date d = new Date();
		String msg = "[" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "] ";
		boolean error = false;
		boolean critical = false;
		
		for(LogLevel tag : tags) {
			msg += tag.asTag() + " ";
			
			if(tag.equals(LogLevel.ERROR)) error = true;
			if(tag.equals(LogLevel.CRITICAL_ERROR)) critical = true;
		}
		
		msg += message;
		
		if(error || critical) {
			System.err.println(msg);
		} else {
			System.out.println(msg);
		}
		
		try {
			writer.write(msg);
			writer.newLine();
			writer.flush();
		} catch(IOException e) {
			e.printStackTrace();
		}
		
		if(critical) {
			Platform.exit();
		}
	}
	
	/**
	 * Perform a warn log message. Alias to {@link Logger#log(String, LogLevel...)}
	 * 
	 * @param message String
	 */
	public void warn(String message) {
		this.log(message, LogLevel.WARNING);
	}
	
	/**
	 * Perform an error log message. Alias to {@link Logger#log(String, LogLevel...)}
	 * 
	 * @param message String
	 */
	public void error(String message) {
		this.log(message, LogLevel.ERROR);
	}
	
	/**
	 * Perform an info log message. Alias to {@link Logger#log(String, LogLevel...)}
	 * 
	 * @param message String
	 */
	public void info(String message) {
		this.log(message, LogLevel.INFO);<commit_msg>Logger now accepts Objects, that it will toString()<commit_after>package net.exodiusmc.blasteroids;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import javafx.application.Platform;
import net.exodiusmc.blasteroids.enums.LogLevel;

/**
 * The Logger class is used to log messages to the console and
 * log file output.
 */
public class Logger {
	private static String filename = "log.txt";
	private static Logger instance;
	private File logfile;
	private BufferedWriter writer;
	
	/**
	 * Returns the associated Logger object
	 * 
	 * @return Logger
	 */
	public static Logger getLogger() {
		if(instance == null) {
			instance = new Logger();
		}
		
		return instance;
	}
	
	@SuppressWarnings("deprecation")
	private Logger() {
		this.logfile = new File(filename);
		
		if(!logfile.exists()) {
			try {
				logfile.createNewFile();
			} catch(IOException e) {
				e.printStackTrace();
			}
		}
		
		try {
			this.writer = new BufferedWriter(new FileWriter(logfile));
		} catch(IOException e) {
			e.printStackTrace();
		}
		
		try {
			Date d = new Date();
			this.writer.write("********** Loading Blasteroids " + Main.getVersion() + " (" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ") **********");
			this.writer.newLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Set the log destination of the logfile output
	 * 
	 * @param name String
	 */
	public static void setLogDestination(String name) {
		filename = name;
	}
	
	/**
	 * Perform a basic log message. Custom LogLevels can be included to alter
	 * the tags inserted before the message
	 * 
	 * @param message String
	 * @param tags LogLevels
	 */
	@SuppressWarnings("deprecation")
	public void log(Object message, LogLevel... tags) {
		Date d = new Date();
		String msg = "[" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + "] ";
		boolean error = false;
		boolean critical = false;
		
		for(LogLevel tag : tags) {
			msg += tag.asTag() + " ";
			
			if(tag.equals(LogLevel.ERROR)) error = true;
			if(tag.equals(LogLevel.CRITICAL_ERROR)) critical = true;
		}
		
		msg += message.toString();
		
		if(error || critical) {
			System.err.println(msg);
		} else {
			System.out.println(msg);
		}
		
		try {
			writer.write(msg);
			writer.newLine();
			writer.flush();
		} catch(IOException e) {
			e.printStackTrace();
		}
		
		if(critical) {
			Platform.exit();
			System.exit(0);
		}
	}
	
	/**
	 * Perform a warn log message. Alias to {@link Logger#log(String, LogLevel...)}
	 * 
	 * @param message String
	 */
	public void warn(Object message) {
		this.log(message, LogLevel.WARNING);
	}
	
	/**
	 * Perform an error log message. Alias to {@link Logger#log(String, LogLevel...)}
	 * 
	 * @param message String
	 */
	public void error(Object message) {
		this.log(message, LogLevel.ERROR);
	}
	
	/**
	 * Perform an info log message. Alias to {@link Logger#log(String, LogLevel...)}
	 * 
	 * @param message String
	 */
	public void info(Object message) {
		this.log(message, LogLevel.INFO);
{'fraction_non_alphanumeric': 0.14826910516002612, 'fraction_numerical': 0.00016329196603527107, 'mean_word_length': 3.172343324250681, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '4734765', 'n_tokens_mistral': 2247, 'n_tokens_neox': 1940, 'n_words': 511}