package alterrs.commons;

import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A static class used for logging.
 * 
 * @author Lazaro
 */
public class LoggingUtil {
	/**
	 * Private constructor as to prevent external initiation.
	 */
	private LoggingUtil() {
	}

	/**
	 * Sets up the logger.
	 */
	public static void setup(String appName) {
		System.out
				.println("//***************************************************************************\\\\");
		System.out.println("   AlterRS [" + appName + "]");
		System.out.println("   Copyright (C) AlterRS Development Team 2011");
		System.out
				.println("   Running " + System.getProperty("os.name")
						+ " on a(n) " + System.getProperty("os.arch")
						+ " architecture");
		System.out.println("   Java version is "
				+ System.getProperty("java.version"));
		System.out
				.println("\\\\***************************************************************************//");
		System.out.println();

		PropertyConfigurator.configure(Constants.DATA_DIR + "log4j.properties");
	}

	/**
	 * Creates a new <code>Logger</code> object and names it based on the class
	 * that this method was called.
	 * 
	 * @return The <code>Logger</code> object
	 */
	public static Logger log() {
		StackTraceElement caller = Thread.currentThread().getStackTrace()[2];
		Logger logger = LoggerFactory.getLogger(caller.getClassName());
		return logger;
	}
}
