The advantage of having per-service API log files is that it is very easy to analyze/monitor what went wrong in this particular Proxy Service a particular REST API defined in the ESB by looking at the service log . Enabling this feature will not terminate the wso2-esb.log
file being keeping the logs about this service, the complete log will contain every log statement including the service logs that you have configured to be logged into a different log file. In other words, the service log files. The API log is an additional log file, which will contain a copy of the logs to that a particular serviceREST API.
Follow the instructions below Below are the configuration details to configure the logs of a particular service (to be more specific a Proxy Service) to be logged into a given log file.
1. See Sample 150 in Proxy Service Samples.
It has a Proxy Service named StockQuoteProxy
.
2. Configure log4j
to log the service REST API called TestAPI
using log4j
properties.
Open <ESB_HOME>/repository/conf/log4j.properties file using your favorite text editor to configure log4j
to log the API specific logs to a file called stock-quote-proxy-service.log
in the logs directory of the ESB installation directory.2.1. Open up the log4j.properties
file found in the /repository/conf
directory of the WSO2 ESB installation directory using your favorite text editor and add . You can configure the logger for either INFO level logs or DEBUG level logs as follows:
Anchor | ||||
---|---|---|---|---|
|
Add the following section to the end of the file to configure the logger for log messages where the Log Category is INFO.
Code Block |
---|
log4j.category.API_LOGGER=INFO, API_APPENDER
log4j.additivity.API_LOGGER=false
log4j.appender.API_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.API_APPENDER.File=${carbon.home}/repository/logs/${instance.log}/wso2-esb-api${instance.log}.log
log4j.appender.API_APPENDER.MaxFileSize=1000KB
log4j.appender.API_APPENDER.MaxBackupIndex=10
log4j.appender.API_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.API_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n</pre>
|
Tip |
---|
The in-sequence of the REST API will need to contain a Log mediator with the Log Category defined as INFO to be able to view logs in the log file. |
Anchor | ||||
---|---|---|---|---|
|
Add the following section to the end of the file starting in a new lineto configure the logger for log messages where the Log Category is DEBUG.
Code Block |
---|
log4j.category.SERVICEAPI_LOGGER.StockQuoteProxyTestAPI=DEBUG, SQTEST_PROXYAPI_APPENDER log4j.additivity.SERVICEAPI_LOGGER.StockQuoteProxyTestAPI=false log4j.appender.SQTEST_PROXYAPI_APPENDER=org.apache.log4j.DailyRollingFileAppender log4j.appender.SQTEST_PROXYAPI_APPENDER.File=${carbon.home}/repository/logs/stock-quote-proxy-service/${instance.log}/TestAPI.log log4j.appender.SQTEST_PROXYAPI_APPENDER.datePattern='.'yyyy-MM-dd-HH-mm log4j.appender.SQTEST_PROXYAPI_APPENDER.layout=org.apache.log4j.PatternLayout log4j.appender.SQTEST_PROXYAPI_APPENDER.layout.ConversionPattern=%d{ISO8601} \[%X{ip}-%X{host}\] \[%t\] %5p %c{1} %m%n |
2.2. Save the file.
3. Try it out. By default, the configuration does not do any logging at run time, so configure the Proxy Service in-sequence to contain a log mediator to log the message at "Full" log level.
Execute the sample client after starting the ESB with sample 150:
Code Block |
---|
$ESB_HOME/bin/wso2esb-samples.sh \-sn 150
|
and the sample axis2 server with the SimpleStockQuote
service deployed on it as per stated in the sample documentation.
4. Inspect the logs directory of the ESB installation directory to see the stock-quote-proxy-service.log file
.
Further to demonstrate the log file rotation this particular logger was configured to rotate the file in each minute when ever there is a log going into the service log, so if you execute the sample client once again after 1 minute you will be able to see the service log file rotation as well.
You can see the source here.
Excerpt | ||
---|---|---|
| ||
Instructions on how to create per-service logs in WSO2 ESB. Source http://blog.ruwan.org/2009/08/wso2-esb-faq-001-per-service-logs-in.html |
Info |
---|
The above configuration creates a log file names |
Tip |
---|
The in-sequence of the REST API will need to contain a Log mediator with the Log Category defined as DEBUG to be able to view logs in the log file. |