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 “” file location in below location.
wso2esb-4.0.3\lib\ or \repository\conf\

  •  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=""/>

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=""/>
<property name=" RequestId" expression="get-property(RequestId)"/>

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 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. File:

# Configure the service logger at INFO level. Writes only run-time/mediation-time audit messages
log4j.appender.SERVICE_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n