/*
 * $Log: LogSender.java,v $
 * Revision 1.1  2008-08-06 16:36:39  europe\L190409
 * moved from pipes to senders package
 *
 */
package nl.nn.adapterframework.senders;

import nl.nn.adapterframework.configuration.ConfigurationException;
import nl.nn.adapterframework.core.ParameterException;
import nl.nn.adapterframework.core.SenderException;
import nl.nn.adapterframework.core.SenderWithParametersBase;
import nl.nn.adapterframework.core.TimeOutException;
import nl.nn.adapterframework.parameters.IParameterHandler;
import nl.nn.adapterframework.parameters.ParameterResolutionContext;
import nl.nn.adapterframework.util.LogUtil;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 * Sender that just logs its message.
 * 
 * <p><b>Configuration:</b>
 * <table border="1">
 * <tr><th>attributes</th><th>description</th><th>default</th></tr>
 * <tr><td>{@link #setLogLevel(String) logLevel}</td><td>level on which messages are logged</td><td>info</td></tr>
 * <tr><td>{@link #setLogCategory(String) logCategory}</td><td>category under which messages are logged</td><td>name of the sender</td></tr>
 * </table>
 * 
 * @author Gerrit van Brakel
 * @since  4.9
 * @version Id
 */
public class LogSender extends SenderWithParametersBase implements IParameterHandler {

	private String logLevel="info";
	private String logCategory=null;

	protected Level level;
	protected Logger log;

	public void configure() throws ConfigurationException {
		super.configure();
		log=LogUtil.getLogger(getLogCategory());
		level=Level.toLevel(getLogLevel());
	}

	public boolean isSynchronous() {
		return true;
	}

	public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
		log.log(level,message);
		
		if (prc != null) {
			try {
				prc.forAllParameters(paramList, this);
			} catch (ParameterException e) {
				throw new SenderException("exception determining value of parameters", e);
			}
		}
		
		return message;
	}

	public void handleParam(String paramName, Object value) {
		log.log(level,"parameter [" + paramName + "] value [" + value + "]");
	}

	public String getLogCategory() {
		if (StringUtils.isNotEmpty(logCategory)) {
			return logCategory;
		}
		if (StringUtils.isNotEmpty(getName())) {
			return getName();
		}
		return this.getClass().getName();
	}

	public void setLogCategory(String string) {
		logCategory = string;
	}

	public String getLogLevel() {
		return logLevel;
	}

	public void setLogLevel(String string) {
		logLevel = string;
	}

	public String toString() {
		return "LogSender ["+getName()+"] logLevel ["+getLogLevel()+"] logCategory ["+logCategory+"]";
	}

}

@@ -24,16 +24,90 @@
 ava,v $%0A
+ * Revision 1.2  2009-09-07 13:32:07  L190409%0A * use log from ancestor%0A *%0A
  * Revis
@@ -123,12 +123,12 @@
 2008
--08-
+/08/
 06 1
@@ -140,22 +140,60 @@
 39  
-europe%5CL190409
+Gerrit van Brakel %3Cgerrit.van.brakel@ibissource.org%3E
 %0A * 
@@ -817,40 +817,8 @@
 vel;
-%0Aimport org.apache.log4j.Logger;
 %0A%0A/*
@@ -1470,16 +1470,16 @@
 =null;%0A%0A
+
 %09protect
@@ -1497,31 +1497,8 @@
 vel;
-%0A%09protected Logger log;
 %0A%0A%09p

use log from ancestor