So first of all lets focus on the requirement, my requirement is to configure the logs of a particular service (to be more specific a proxy service) to be logged into a given log file. The advantage of having per-service log files is that it is very easy to analyse/monitor what went wrong in this particular proxy service 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 is a complete log and 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 is an additional log file which will contain a copy of the logs to that particular service.
Then, how can you configure this in the WSO2 ESB. So, lets assume that we are referring to the sample 150 of the WSO2 ESB, which has a proxy service named StockQuoteProxy. Now we need to configure log4j to log the service specific logs to a file called stock-quote-proxy-service.log in the logs directory of the ESB installation directory. Open up the log4j.properties file found at the lib directory of the WSO2 ESB installation directory using your favourite text editor and add the following section to the end of the file starting in a new line;
log4j.category.SERVICE_LOGGER.StockQuoteProxy=DEBUG, SQ_PROXY_APPENDERWell, save the file and you are done with the configuration, and now it is time to try it out. By default the sample 150 configuration doesn't do any logging at run time. So go ahead and configure the proxy service in-sequence to contain a log mediator to log the message at "Full" log level.
log4j.additivity.SERVICE_LOGGER.StockQuoteProxy=false
log4j.appender.SQ_PROXY_APPENDER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.SQ_PROXY_APPENDER.File=logs/stock-quote-proxy-service.log
log4j.appender.SQ_PROXY_APPENDER.datePattern='.'yyyy-MM-dd-HH-mm
log4j.appender.SQ_PROXY_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.SQ_PROXY_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n
Execute the sample client after starting the ESB with the sample 150;
$ESB_HOME/bin/wso2esb-samples.sh -sn 150and the sample axis2 server with SimpleStockQuote service deployed on it as per stated in the sample documentation.
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 I have configured this particular logger 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.

0 comments:
Post a Comment