package common;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import error.ExceptionUtil;

/**
 * Logger for system
 */
public class LoggerUtil {
	private static final String PROPERTIES_FILE_LOCATION = "resources/logging.properties";

	private LoggerUtil() {
		throw new UnsupportedOperationException("Utility class");
	}

	/**
	 * Get a logger used for the respective class
	 *
	 * @param loggingClass the class that this logging is used for
	 * @return the logger for this class
	 */
	public static Logger getLoggerForClass(Class<?> loggingClass) {
		LogManager.getLogManager().reset();

		try {
			LogManager.getLogManager()
					.readConfiguration(new FileInputStream(PROPERTIES_FILE_LOCATION));
		} catch (IOException | SecurityException e) {
			ExceptionUtil.handleCriticalException(e, "Logger failed to read config file");
		}

		return Logger.getLogger(loggingClass.getClass().getName());
	}
}
