I made some changes to LogMediator, LogMediatorFactory and LogMediatorSerializer by adding the quick log feature which allows to add quickly log a literal or expression. Patch file is attached.
Examples; <log value = 'value' /> <log expression = "XPath expression" /> <log [(value="literal" | expression="xpath")] [level="string"] [separator="string"]> <property name="string" (value="literal" | expression="xpath")/>* </log>
Index: modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorSerializer.java =================================================================== --- modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorSerializer.java (revision 988018) +++ modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorSerializer.java (revision ) @@ -42,6 +42,16 @@ OMElement log = fac.createOMElement("log", synNS); saveTracingState(log,mediator); + //Serialize the quick message + if(mediator.getQuickMessage() != null){ + if(mediator.getQuickMessage().getKeyValue() != null){ + log.addAttribute(fac.createOMAttribute("value",nullNS,mediator.getQuickMessage().getKeyValue() )); + }else if(mediator.getQuickMessage().getExpression() != null){ + SynapseXPathSerializer.serializeXPath(mediator.getQuickMessage().getExpression(),log,"expression"); + } + } + + if (mediator.getLogLevel() != LogMediator.SIMPLE) { log.addAttribute(fac.createOMAttribute( "level", nullNS, Index: modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java =================================================================== --- modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java (revision 909373) +++ modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java (revision ) @@ -24,8 +24,11 @@ import org.apache.axiom.soap.SOAPHeaderBlock; import org.apache.synapse.MessageContext; import org.apache.synapse.SynapseLog; +import org.apache.synapse.config.xml.SynapseXPathFactory; import org.apache.synapse.mediators.AbstractMediator; import org.apache.synapse.mediators.MediatorProperty; +import org.apache.synapse.mediators.Value; +import org.apache.synapse.util.xpath.SynapseXPath; import java.util.ArrayList; import java.util.Iterator; @@ -57,8 +60,11 @@ public static final int CATEGORY_ERROR = 4; public static final int CATEGORY_FATAL = 5; + public static final String DEFAULT_SEP = ", "; + private Value quickMessage = null; + /** The default log level is set to SIMPLE */ private int logLevel = SIMPLE; /** The separator for which used to separate logging information */ @@ -186,6 +192,13 @@ } private void setCustomProperties(StringBuffer sb, MessageContext synCtx) { + + //append the quick log message + if(quickMessage != null){ + sb.append(" Log Message = "+ (quickMessage.getKeyValue() != null ? quickMessage.getKeyValue() : + quickMessage.getExpression().stringValueOf(synCtx))); + } + if (properties != null && !properties.isEmpty()) { for (MediatorProperty property : properties) { if(property != null){ @@ -245,4 +258,13 @@ return retStr; } } + + + public Value getQuickMessage() { + return quickMessage; -} + } + + public void setQuickMessage(Value quickMessage) { + this.quickMessage = quickMessage; + } +} Index: modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorFactory.java =================================================================== --- modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorFactory.java (revision 999840) +++ modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorFactory.java (revision ) @@ -22,7 +22,10 @@ import org.apache.axiom.om.OMAttribute; import org.apache.axiom.om.OMElement; import org.apache.synapse.Mediator; +import org.apache.synapse.mediators.Value; import org.apache.synapse.mediators.builtin.LogMediator; +import org.apache.synapse.util.xpath.SynapseXPath; +import org.jaxen.JaxenException; import javax.xml.namespace.QName; import java.util.Properties; @@ -52,6 +55,8 @@ private static final QName ATT_LEVEL = new QName("level"); private static final QName ATT_SEPERATOR = new QName("separator"); private static final QName ATT_CATEGORY = new QName("category"); + private static final QName ATT_QUICK_VALUE = new QName("value"); + private static final QName ATT_QUICK_EXPRESSION = new QName("expression"); public QName getTagQName() { return LOG_Q; @@ -64,7 +69,27 @@ // after successfully creating the mediator // set its common attributes such as tracing etc processAuditStatus(logMediator,elem); - + + //Set the quick log message + OMAttribute value = elem.getAttribute(ATT_QUICK_VALUE); + OMAttribute expression = elem.getAttribute(ATT_QUICK_EXPRESSION); + Value logMessage; + + if(value !=null){ + logMessage = new Value(value.getAttributeValue()); + logMediator.setQuickMessage(logMessage); + + }else if(expression != null){ + try { + SynapseXPath xPathExpression = SynapseXPathFactory.getSynapseXPath(elem,expression.getAttributeValue()); + logMessage = new Value(xPathExpression); + logMediator.setQuickMessage(logMessage); + } catch (JaxenException e) { + handleException("Invalid XPath specified for the source attribute : " + + expression.getAttributeValue()); + } + } + // Set the high level set of properties to be logged (i.e. log level) OMAttribute level = elem.getAttribute(ATT_LEVEL); if (level != null) {
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@synapse.apache.org For additional commands, e-mail: dev-h...@synapse.apache.org