简体   繁体   中英

Log Configuration in WSO2

So i'm working on PER-API log configuration in WSO2, in order to log REQUEST/RESPONSE for an API call, we need to

  1. Modify the file log4j.properties in < APIM HOME >\\repository\\conf by adding the following lines to it

log4j.appender.TestAPI_APPENDER=org.apache.log4j.RollingFileAppender log4j.appender.TestAPI_APPENDER.File=${carbon.home}/repository/logs/PerAPI/${instance.log}/wso2-APILogs-service${instance.log}.log log4j.appender.TestAPI_APPENDER.MaxFileSize=1000KB log4j.appender.TestAPI_APPENDER.MaxBackupIndex=10 log4j.appender.TestAPI_APPENDER.layout=org.apache.log4j.PatternLayout log4j.appender.TestAPI_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n%n log4j.category.API_LOGGER.admin-- APINAME = TRACE, TestAPI_APPENDER

  1. It logs the following details to a .txt file which is pretty comprehensive and cool

在此处输入图片说明

However i do have some questions that i'm stuck in and would like help in, here are they

  • The HTTP Status Code for the response is not being logged here which i badly need, I've looked here and it says to use %s - HTTP status code of the response however when i put the character %s in the log4j.properties ConversionPattern, those characters are printed as they are, how can i achieve this?
  • Secondly, does wso2 has some sort of portal in order to visualize these custom logs?
  • Thirdly, i need to put a line at the end of request/response (4 entries per API CALL) log lines and i'm unable to find any solution, if i hardcode a line into the log4j.properties ConversionPattern, i suppose it would print after each entry, please help?!

Thank you

Please find the below answers for your questions

By enabling wire logs settings you can easily track the HTTP Status Code for the response. You can enable the header and wirelogs by un-commenting following lines in log4j.properties file ( located at: \\repository\\conf )

log4j.logger.org.apache.synapse.transport.http.headers=DEBUG
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG

The third Question, you can achieve this by using log mediator in In-sequence(print a line in request) and out-sequence(print a line in response).For an example you can use custom log in your api synapse configuration file as follows (here I use this custom log in in sequence)

<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--TwitterSearch:v1.0.0--In">
<log level="custom">
            <property name="test" value="your value goes here……….” />
  </log> 
</sequence>
  • You can enable wirelogs to track the request and responses of the API when it is getting invoked. To do that uncomment following line in log4j.properties file.

    log4j.logger.org.apache.synapse.transport.http.wire=DEBUG

Furthermore if you want to log the http messages you can uncomment following line as well.

log4j.logger.org.apache.synapse.transport.http.headers=DEBUG


  • If you want to print a customized log for the API, you can use the Log mediator and add a Log mediator as a mediation extension per API with the required log to be printed in the synapse configuration of the API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM