Wednesday, October 14, 2015

How to use log mediator in WSO2 ESB

You can log all the information which is mediated in your ESB logic written in synapse. You can define the category of the logs, this is same as other programming language like DEBUG, ERROR, and INFO etc.

All the below category you can define in “log4j.properties” file location in below location.
wso2esb-4.0.3\lib\log4j.properties or \repository\conf\log4j.properties

  •  TRACE: It is similar to DEBUG but provide more information it is normally used in the time of deployment
  • DEBUG: It provides the most useful information when application is executed for debugging
  • INFO: It provides high level information
  • WORN: It generates the logs in case of harmful situation
  • ERROR: It provides error information in your application
  • FATEL: very severe error events that will presumably lead the application to abort

You can define the log level as well including Full, simple, header and custom. Custom is used only for the property mediator however full includes all attribute including “simple” log level

Example (Full):

<log level="full">
<property name="RequestId" expression="//swj:RequestId/text()" type="STRING" xmlns:swj="http://shriwithjavablogspot.co.nz/logpropertyexample/"/>
</log>

In this example we are trying to get the value of RequestId from the request payload, because property value is being fetched from the request expression so we need to pass xml namespace as well to get the value of RequestId.

Example (Custom):

<log level="Custom">
<property name="RequestId" expression="//swj:RequestId/text()" type="STRING" xmlns:swj="http://shriwithjavablogspot.co.nz/logpropertyexample/"/>
<property name=" RequestId" expression="get-property(RequestId)"/>
</log>

In above example we are trying to get again property value from expression and as well as from property mediator.

You can change your log setting in log4j.property file like INFO, DEBUG and ERROR etc. there are some other configuration like if you want to create another separate file you can put it into property file and you will see that another separation file will be created.

log4j.property File:

# Configure the service logger at INFO level. Writes only run-time/mediation-time audit messages
log4j.category.SERVICE_LOGGER=INFO, SERVICE_APPENDER
log4j.additivity.SERVICE_LOGGER=false
log4j.appender.SERVICE_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.SERVICE_APPENDER.File=${carbon.home}/repository/logs/${instance.log}/wso2-esb-service${instance.log}.log
log4j.appender.SERVICE_APPENDER.MaxFileSize=1000KB
log4j.appender.SERVICE_APPENDER.MaxBackupIndex=10
log4j.appender.SERVICE_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.SERVICE_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n



No comments:

Post a Comment