Thing which seemed very Thingish inside you is quite different when it gets out into the open and has other people looking at it

Friday, August 3, 2012

How to create service specific logs for WSO2 ESB

In this post I am going to talk how you can create differant log files depending on your proxy service using WSO2 ESB. Lets say you have a proxy service deployed in ESB and you need to filter out the logs generated by that given proxy service. You can  do this in three easy steps using wso2 logging-mgt feature.

Step 1 - Creating a proxy service with LogMediator

In order to try this out you need to create a proxy service which uses log-mediator so we can easily generate logs comming from that proxy service.

So this is my proxy service

<proxy xmlns="" name="MyProxyService" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">

        <log level="full">
           <property name="MESSAGE" value="****************Inside in sequance*********************" />
        <log level="full">
           <property name="Message2" value="************Inside out sequance ************************" />
        <send />

Step2 - Adding Service Level log appender to send logs to differant log file location

WSo2 logging-mgt feature use standard apache log4j framework therefore, you need to change log4j properties in order to create appenders. We will create a new appender call MY_PROXY_APPENDER

log4j.appender.MY_PROXY_APPENDER.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%

Here we are defining what kind of an appender, we will use DailyRollingFileAppender you can change the appender type depending on your need such as DBAppender,SyslogAppender etc And also you need to give appender properties like file location, which patternlayout you need to use and the log pattern you need. ALl these are configurable depending on your need.

Step 3 - Adding your logger in the root logger.

You need to aknowlege the newly created Appender in log4j.logger to map MyProxyServic to the SERVICE_LOGGER. The logger will be under Service_Logger so you need to specify your appender as shown below.

 log4j.category.SERVICE_LOGGER.MyProxyService =INFO, PROXY_APPENDER

Thats it!! you can go to {CARBON_HOME}/repository/logs to view your newly created proxy service specific log file!!!!

No comments:

Post a Comment