Saturday, January 21, 2017

Separating logs for API's based on API Names in WSO2 APIM 1.10

This article explains how we can separate the logs for each API's based on their API names. It is possible using log4j, but the limitation is you need to provide the api name in the log4j.properties file. You can achieve this using the below configuration in log4j.properties file.

Here, important thing is the name of the API, you should mention as admin--TestAPI_10 in the log4j.properties file. For example, if you are creating a api TestAPI_10 then the name should specify in log4j.properties is  admin--TestAPI_10.

log4j.logger.API_LOGGER.admin--TestAPI_10=DEBUG, TestAPI_10
log4j.logger.API_LOGGER.admin--TestAPI_11=DEBUG, TestAPI_11

log4j.appender.TestAPI_10=org.apache.log4j.DailyRollingFileAppender
log4j.appender.TestAPI_10.Append = true
log4j.appender.TestAPI_10.File=${carbon.home}/repository/logs/TestAPI_10.log
log4j.appender.TestAPI_10.layout=org.apache.log4j.PatternLayout
log4j.appender.TestAPI_10.layout.ConversionPattern=TID: [%d] %5p {%c} - %x %m {%c}%n

log4j.appender.TestAPI_11=org.apache.log4j.DailyRollingFileAppender
log4j.appender.TestAPI_11.Append = true
log4j.appender.TestAPI_11.File=${carbon.home}/repository/logs/TestAPI_11.log
log4j.appender.TestAPI_11.layout=org.apache.log4j.PatternLayout
log4j.appender.TestAPI_11.layout.ConversionPattern=TID: [%d] %5p {%c} - %x %m {%c}%n

The result log at TestAPI_10.log is:

TID: [2017-01-20 17:05:55,351]  INFO {API_LOGGER.admin--TestAPI_10} -  Initializing API: admin--TestAPI_10:v1.0.0 {API_LOGGER.admin--TestAPI_10}
TID: [2017-01-20 17:09:02,388]  INFO {API_LOGGER.admin--TestAPI_10} -  Initializing API: admin--TestAPI_10:v1.0.0 {API_LOGGER.admin--TestAPI_10}
TID: [2017-01-20 17:09:04,389]  INFO {API_LOGGER.admin--TestAPI_10} -  Destroying API: admin--TestAPI_10:v1.0.0 {API_LOGGER.admin--TestAPI_10}
TID: [2017-01-20 17:09:31,084]  INFO {API_LOGGER.admin--TestAPI_10} -  To: /testAPI_10/1.0.0, MessageID: urn:uuid:0e535d55-ee59-47b5-95b4-be8f6f574234, Direction: request, Envelope: TestAPI_10 {API_LOGGER.admin--TestAPI_10}

The result log at TestAPI_11.log is:

TID: [2017-01-20 17:10:57,702]  INFO {API_LOGGER.admin--TestAPI_11} -  Initializing API: admin--TestAPI_11:v1.0.0 {API_LOGGER.admin--TestAPI_11}
TID: [2017-01-20 17:12:05,909]  INFO {API_LOGGER.admin--TestAPI_11} -  Initializing API: admin--TestAPI_11:v1.0.0 {API_LOGGER.admin--TestAPI_11}
TID: [2017-01-20 17:12:07,910]  INFO {API_LOGGER.admin--TestAPI_11} -  Destroying API: admin--TestAPI_11:v1.0.0 {API_LOGGER.admin--TestAPI_11}
TID: [2017-01-20 17:12:17,324]  INFO {API_LOGGER.admin--TestAPI_11} -  To: /testAPI_11/1.0.0, MessageID: urn:uuid:a3fd5281-3382-4df2-9195-84e0192e0c0b, Direction: request, Envelope: TestAPI_11 {API_LOGGER.admin--TestAPI_11}

No comments:

Post a Comment