/* Copyright 2013 Nationale-Nederlanden Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ 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; /** * 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 */ public class LogSender extends SenderWithParametersBase implements IParameterHandler { private String logLevel="info"; private String logCategory=null; protected Level level; 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+"]"; } }