diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorSerializer.java b/modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorSerializer.java index 841d186055..aa48ffd686 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorSerializer.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/LogMediatorSerializer.java @@ -44,13 +44,25 @@ public OMElement serializeSpecificMediator(Mediator m) { OMElement log = fac.createOMElement("log", synNS); saveTracingState(log,mediator); - if (mediator.getLogLevel() != LogMediator.MESSAGE_TEMPLATE) { - log.addAttribute(fac.createOMAttribute( - "level", nullNS, - mediator.getLogLevel() == LogMediator.HEADERS ? "headers" : - mediator.getLogLevel() == LogMediator.FULL ? "full" : - mediator.getLogLevel() == LogMediator.CUSTOM ? "custom" : "simple" - )); + String logLevel = ""; + switch (mediator.getLogLevel()) { + case LogMediator.CUSTOM: + logLevel = "custom"; + break; + case LogMediator.HEADERS: + logLevel = "headers"; + break; + case LogMediator.FULL: + logLevel = "full"; + break; + case LogMediator.MESSAGE_TEMPLATE: + OMElement messageElement = fac.createOMElement("message", synNS); + messageElement.setText(mediator.getMessageTemplate()); + log.addChild(messageElement); + break; + } + if (StringUtils.isNotBlank(logLevel)) { + log.addAttribute(fac.createOMAttribute("level", nullNS, logLevel)); } if (mediator.getCategory() != LogMediator.CATEGORY_INFO) { @@ -75,12 +87,6 @@ public OMElement serializeSpecificMediator(Mediator m) { "separator", nullNS, mediator.getSeparator())); } - if (StringUtils.isNotBlank(mediator.getMessageTemplate())) { - OMElement onCompleteElem = fac.createOMElement("message", synNS); - onCompleteElem.setText(mediator.getMessageTemplate()); - log.addChild(onCompleteElem); - } - super.serializeProperties(log, mediator.getProperties()); serializeComments(log, mediator.getCommentsList()); diff --git a/modules/core/src/test/java/org/apache/synapse/config/xml/LogMediatorSerializationTest.java b/modules/core/src/test/java/org/apache/synapse/config/xml/LogMediatorSerializationTest.java index 60862be49a..8d9e4ca7bf 100644 --- a/modules/core/src/test/java/org/apache/synapse/config/xml/LogMediatorSerializationTest.java +++ b/modules/core/src/test/java/org/apache/synapse/config/xml/LogMediatorSerializationTest.java @@ -55,6 +55,7 @@ public void testLogMediatorSerializationWithTemplate() throws Exception { assertTrue(serialization(getXmlOfLogMediatorWithTemplate(), logMediatorFactory, logMediatorSerializer)); assertTrue(serialization(getXmlOfLogMediatorWithTemplateAndProps(), logMediatorFactory, logMediatorSerializer)); + assertTrue(serialization(getXmlOfLogMediatorWithEmptyTemplateAndProps(), logMediatorFactory, logMediatorSerializer)); } public void testLogMediatorSerializationSenarioOne() throws Exception { @@ -147,6 +148,12 @@ private String getXmlOfLogMediatorWithTemplateAndProps() { ""; } + private String getXmlOfLogMediatorWithEmptyTemplateAndProps() { + return "" + + "" + + ""; + } + private String getXmlOfMediatorScenarioOneA(String level) { return ""; @@ -161,7 +168,7 @@ private String getXmlOfMediatorScenarioTwo(String level, String seperator) { } private String getXmlOfMediatorScenarioThree(String category) { - return ""; }