我需要记录特定 API 的调试级别。我为示例 API 使用单独的日志文件:http://localhost:8280/test001。我已经为这个要求使用了每个 API log4j 属性(参考:https ://docs.wso2.com/display/ESB490/Per-API+Logs+in+WSO2+ESB )。 ISSUE:在文件中找不到位于调用中介之后的调试级别日志。
我的 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 文件中(这确保了调用中介之后的执行)。
注意: 但是我可以保证以下几点:
- 在调用调解器执行之后编写的调解流程。(我可以在控制台中看到信息日志。)。
呼叫调解员成功响应值。
如果没有 API 中的调用中介,所有 DEBUG 日志行都在 commonApi.log 文件中。(按预期工作)
- 无序调试日志以任何方式存在于文件中。(按预期工作)
提前致谢。!