All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.asher_stern.crf.utilities.log4j.Log4jInit Maven / Gradle / Ivy

Go to download

Implementation of linear-chain Conditional Random Fields (CRF) in pure Java

There is a newer version: 1.2.0
Show newest version
package com.asher_stern.crf.utilities.log4j;

import java.util.Enumeration;

import org.apache.log4j.Appender;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 * Initializes Log4j: log messages will be printed to screen with prefix of "INFO - ", "DEBUG - ", etc.
 * 
 * @author Asher Stern
 * Date: Nov 4, 2014
 *
 */
public class Log4jInit
{
	
	public static void init()
	{
		init(Level.INFO);
	}
	
	public static void init(Level level)
	{
		if (!alreadyInitialized)
		{
			synchronized(Log4jInit.class)
			{
				if (!alreadyInitialized)
				{
					BasicConfigurator.configure();
					Logger.getRootLogger().setLevel(level);
					
					Enumeration enumAppenders = Logger.getRootLogger().getAllAppenders();
					while (enumAppenders.hasMoreElements())
					{
						Appender appender = (Appender) enumAppenders.nextElement();
						appender.setLayout(new VerySimpleLayout());
					}
					
					alreadyInitialized = true;
				}
			}
		}

	}
	
	private static boolean alreadyInitialized = false;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy