package de.uka.ipd.consensus.foundation.logging;

import java.util.Properties;

import de.uka.ipd.consensus.foundation.ConsensusFoundationModule;

/**
 * <p>The LoggingManager is used by all other components to log debug and information messages.
 * Furthermore, an implementation can register itself as a listener on other components and log their actions automatically.</p>
 * 
 * <p>The LoggingManager implementation can be configured with the key <code>cf.loggingmanager</code>
 * in the <code>ConsensusFoundation.properties</code> configuration file. It's a core component and not optional.</p>
 * 
 * <p>The implementation is loaded by the <code>ConsensusFoundation</code> constructor. For successful instantiation,
 * the LoggingManager implementation must provide a default constructor without arguments.</p>
 * 
 * @author Thomas Much
 * @version 2006-06-14
 * @see de.uka.ipd.consensus.foundation.ConsensusFoundation
 */
public interface LoggingManager extends ConsensusFoundationModule {

	/**
	 * The loglevel at which all messages are logged.
	 * @see #setLevel(int)
	 */
	public static final int LEVEL_ALL   = 6;

	
	/**
	 * The loglevel at which fatal, error, warning, information and debug messages are logged.
	 * @see #setLevel(int)
	 */
	public static final int LEVEL_DEBUG = 5;

	
	/**
	 * The loglevel at which fatal, error, warning and information messages are logged.
	 * @see #setLevel(int)
	 */
	public static final int LEVEL_INFO  = 4;

	
	/**
	 * The loglevel at which fatal, error and warning messages are logged.
	 * @see #setLevel(int)
	 */
	public static final int LEVEL_WARN  = 3;

	
	/**
	 * The loglevel at which fatal and error messages are logged.
	 * @see #setLevel(int)
	 */
	public static final int LEVEL_ERROR = 2;

	
	/**
	 * The loglevel at which only fatal messages are logged.
	 * @see #setLevel(int)
	 */
	public static final int LEVEL_FATAL = 1;

	
	/**
	 * The loglevel at which no messages are logged at all.
	 * @see #setLevel(int)
	 */
	public static final int LEVEL_OFF   = 0;

	
	/**
	 * This method is called by the <code>ConsensusFoundation</code> constructor to initialize the LoggingManager.
	 * @param config all entries from <code>ConsensusFoundation.properties</code>
	 * @throws Exception if any error occurs (startup of the application is aborted in this case)
	 * @see de.uka.ipd.consensus.foundation.ConsensusFoundation#ConsensusFoundation()
	 */
	public void init(Properties config) throws Exception;

	
	/**
	 * Changes the loglevel. See the loglevel constants in this interface.
	 * @param level the new loglevel
	 * @see #getLevel()
	 */
	public void setLevel(int level);
	
	
	/**
	 * <p>Returns the current loglevel. See the loglevel constants in this interface.
	 * <p>To check whether a certain level is active, use one of the <code>isXXXEnabled()</code> methods.</p>
	 * @return the current loglevel
	 * @see #setLevel(int)
	 */
	public int getLevel();
	
	
	/**
	 * Checks if the debug loglevel is enabled.
	 * This is true if a higher level (all) is enabled, too.
	 * @return <code>true</code> if debugging messages are logged, <code>false</code> otherwise
	 * @see #LEVEL_DEBUG
	 */
	public boolean isDebugEnabled();
	
	
	/**
	 * Checks if the info loglevel is enabled.
	 * This is true if a higher level (debug, all) is enabled, too.
	 * @return <code>true</code> if info messages are logged, <code>false</code> otherwise
	 * @see #LEVEL_INFO
	 */
	public boolean isInfoEnabled();
	
	
	/**
	 * Checks if the warning loglevel is enabled.
	 * This is true if a higher level (info, debug, all) is enabled, too.
	 * @return <code>true</code> if warning messages are logged, <code>false</code> otherwise
	 * @see #LEVEL_WARN
	 */
	public boolean isWarnEnabled();
	
	
	/**
	 * Checks if the error loglevel is enabled.
	 * This is true if a higher level (warn, info, debug, all) is enabled, too.
	 * @return <code>true</code> if error messages are logged, <code>false</code> otherwise
	 * @see #LEVEL_ERROR
	 */
	public boolean isErrorEnabled();
	
	
	/**
	 * Checks if the fatal loglevel is enabled.
	 * This is true if a higher level (error, warn, info, debug, all) is enabled, too.
	 * @return <code>true</code> if fatal messages are logged, <code>false</code> otherwise
	 * @see #LEVEL_FATAL
	 */
	public boolean isFatalEnabled();

	
	/**
	 * Logs the given message if the debug loglevel is active.
	 * @param message the message to be logged
	 * @see #isDebugEnabled()
	 */
	public void debug(Object message);

	
	/**
	 * Logs the given message if the info loglevel is active.
	 * @param message the message to be logged
	 * @see #isInfoEnabled()
	 */
	public void info(Object message);

	
	/**
	 * Logs the given message if the warning loglevel is active.
	 * @param message the message to be logged
	 * @see #isWarnEnabled()
	 */
	public void warn(Object message);

	
	/**
	 * Logs the given message if the error loglevel is active.
	 * @param message the message to be logged
	 * @see #isErrorEnabled()
	 */
	public void error(Object message);

	
	/**
	 * Logs the given message if the fatal loglevel is active.
	 * @param message the message to be logged
	 * @see #isFatalEnabled()
	 */
	public void fatal(Object message);

}
