您正在使用WSO2 ESB 4.7.0
我创建了一个简单的代理,并使用类介体添加了几个nums,如下所示。
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Add_class"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="messagetype"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="ContentType" value="application/json" scope="axis2"/>
<property name="FORCE_ERROR_ON_SOAP_FAULT" value="true"/>
<property name="Maths" expression="//Maths/text()"/>
<property name="Eng" expression="//Eng/text()"/>
<property name="Hindi" expression="//Hindi/text()"/>
<log level="custom">
<property name="LogLocation" value="Add_class"/>
</log>
<class name="org.example.mediator.MailEsb"/>
<filter xpath="get-property('ToatalMarks')=''">
<then>
<payloadFactory media-type="xml">
<format>
<ResponseJSON xmlns="">
<Body>
<Datalist>ToatalMarks Not Found</Datalist>
</Body>
<Status>404</Status>
</ResponseJSON>
</format>
<args/>
</payloadFactory>
<log level="custom">
<property name="LogLocation" value="Add_class"/>
<property name="ToatalMarks" expression="get-property('ToatalMarks')"/>
</log>
<send/>
</then>
<else>
<payloadFactory media-type="xml">
<format>
<ResponseJSON xmlns="">
<Body>
<Datalist>ToatalMarks of the subjets is</Datalist>
<Sum>$1</Sum>
</Body>
<Status>404</Status>
</ResponseJSON>
</format>
<args>
<arg evaluator="xml" expression="get-property('ToatalMarks')"/>
</args>
</payloadFactory>
<log level="custom">
<property name="LogLocation" value="Add_class"/>
<property name="ToatalMarks" expression="get-property('ToatalMarks')"/>
</log>
<send/>
</else>
</filter>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>
类:
package org.example.mediator;
import java.util.Map;
import java.util.Properties;
import java.util.Iterator;
import java.util.Set;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.synapse.ManagedLifecycle;
import org.apache.synapse.MessageContext;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.mediators.AbstractMediator;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MailEsb extends AbstractMediator implements
ManagedLifecycle
{
public boolean mediate(MessageContext synCtx) {
log.info("LogLocation = "+getClass().getName()+",ProxyName = "+synCtx.getProperty("proxy.name")+
",Usercode = "+synCtx.getProperty("usercode")+",Clientid = "+synCtx.getProperty("clientid")+
",Position = START");
try {
String Eng=""+synCtx.getProperty("Eng");
String Maths=""+synCtx.getProperty("Maths");
String Hindi=""+synCtx.getProperty("Hindi");
int T= Integer.parseInt(Eng) + Integer.parseInt(Maths) + Integer.parseInt(Hindi);
synCtx.setProperty("ToatalMarks", T);
log.info("LogLocation = "+getClass().getName()+", Total of all the subjects is= " +T);
}
catch (Exception e) {
log.info( "LogLocation = "+getClass().getName()+", mail sending exception: "+e+e.getMessage());
}
return true;
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void init(SynapseEnvironment arg0) {
// TODO Auto-generated method stub
}
}
我已经在我的类代码中定义了日志以反映在我的Wso2 esb服务器中但未能这样做....
谢谢!
答案 0 :(得分:0)
您还需要使用正确的记录器
更改您的课程“private static final Log log = LogFactory.getLog(MailEsb.class);”
因此,您可以正确管理日志,也应该
log.error not log.info