我需要记录特定API的DEBUG级别。 我为示例API使用单独的日志文件:http://localhost:8280/test001。我已经为此要求使用了每个API log4j属性(参考:https://docs.wso2.com/display/ESB490/Per-API+Logs+in+WSO2+ESB)。 ISSUE:在调用介体之后放置的DEBUG级别日志无法在文件中找到。
我的API:test.xml
<?xml version="1.0" encoding="UTF-8"?><api context="/test001" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET"><inSequence>
<log category="DEBUG" level="custom">
<property name="DEBUG category" value="DEBUG LOG BEFORE CALL MEDIATOR"/>
</log>
<call>
<endpoint>
<http method="get" uri-template="http://localhost:8280/sample001"/>
</endpoint>
</call>
<log category="DEBUG" level="custom">
<property name="DEBUG category" value="DEBUG LOG AFTER CALL MEDIATOR"/>
</log>
<log level="custom">
<property name="INFO category" value="INFO LOG AFTER CALL MEDIATOR"/>
</log>
<payloadFactory media-type="xml">
<format>
<test>SUCCESS</test>
</format>
<args/>
</payloadFactory>
<loopback description="loop backing to out-sequence"/>
</inSequence>
<outSequence>
<log category="DEBUG" level="custom">
<property name="DEBUG category" value=" DBUG OUT SEQUENCE"/>
</log>
<log level="custom">
<property name="INFO category" value="INFO OUT SEUENCE"/>
</log>
<send/>
</outSequence>
<faultSequence>
<log category="DEBUG" level="custom">
<property name="log DEBUG" value=" DBUG FAULT SEQUENCE"/>
</log>
<log level="custom">
<property name="log DEBUG" value="INFO FAULT SEUENCE"/>
</log>
</faultSequence></resource></api>
我的log4j配置wso2ei-6.1.1 \ conf \ log4j.properties:
log4j.category.API_LOGGER.test =DEBUG,COMMON_API_APPENDER
log4j.appender.test.Append = true
log4j.appender.COMMON_API_APPENDER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.COMMON_API_APPENDER.File=${carbon.home}/repository/logs/commonApi.log
log4j.appender.COMMON_API_APPENDER.datePattern='.'yyyy-MM-dd
log4j.appender.COMMON_API_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.COMMON_API_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n
注意:其他属性在log4j.properties文件中未更改
commonApi.log:
2017-11-21 19:42:06,502 [-] [localhost-startStop-1] INFO test Initializing API: test
2017-11-21 19:43:21,703 [-] [PassThroughMessageProcessor-1] DEBUG test DEBUG category = DEBUG LOG BEFORE CALL MEDIATOR
2017-11-21 19:43:22,021 [-] [PassThroughMessageProcessor-3] DEBUG test DEBUG category = DBUG OUT SEQUENCE
2017-11-21 19:43:22,021 [-] [PassThroughMessageProcessor-3] INFO test INFO category = INFO OUT SEUENCE
正如您在API代码中看到的,记录行:
DEBUG category = DEBUG LOG AFTER CALL MEDIATOR
commonApi.log文件中缺少。
wso2carbon.log:
TID: [-1234] [] [2017-11-21 19:43:21,703] DEBUG {API_LOGGER.test} - DEBUG category = DEBUG LOG BEFORE CALL MEDIATOR {API_LOGGER.test}
TID: [-1234] [] [2017-11-21 19:43:21,711] INFO {org.apache.synapse.core.axis2.TimeoutHandler} - This engine will expire all callbacks after GLOBAL_TIMEOUT: 120 seconds, irrespective of the timeout action, after the specified or optional timeout {org.apache.synapse.core.axis2.TimeoutHandler}
TID: [-1234] [] [2017-11-21 19:43:22,004] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /sample001, MessageID: urn:uuid:c7c63feb-9c3f-46f7-b3cb-9a9d0b4fb82e, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-11-21 19:43:22,019] INFO {org.apache.synapse.mediators.builtin.LogMediator} - INFO category = INFO LOG AFTER CALL MEDIATOR {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-11-21 19:43:22,021] DEBUG {API_LOGGER.test} - DEBUG category = DBUG OUT SEQUENCE {API_LOGGER.test}
TID: [-1234] [] [2017-11-21 19:43:22,021] INFO {org.apache.synapse.mediators.builtin.LogMediator} - INFO category = INFO OUT SEUENCE {org.apache.synapse.mediators.builtin.LogMediator}
TID: [-1234] [] [2017-11-21 19:43:22,021] INFO {API_LOGGER.test} - INFO category = INFO OUT SEUENCE {API_LOGGER.test}
但是你可以看到信息日志行:
INFO category = INFO LOG AFTER CALL MEDIATOR
在wso2carbon.log文件中(这可以确保在call-mediator之后执行)。
注意: 但是我可以保证下面的事情:
调用介体成功响应值。
如果没有API中的call-mediator,所有DEBUG日志行都在commonApi.log文件中。(按预期工作)
提前致谢。
答案 0 :(得分:1)
您确定需要在非阻塞模式下使用呼叫中介(默认情况下,呼叫中介是非阻塞的)吗?如果您将模式更改为阻止,则代码可以正常工作。
<call blocking="true">
或者您可以默认使用阻止的<callout>
介体来获得相同的结果。
由于INFO日志正在运行,我认为这可能是WSO2 IE6中的一个Bug。