How to bridge sl4j and log4j in BE

How to bridge sl4j and log4j in BE

book

Article ID: KB0073067

calendar_today

Updated On:

Products Versions
TIBCO BusinessEvents Enterprise Edition 5.6 and 6.1

Description

Use case:
There is a need to use some existing custom Java code in a BE application. This code makes use of the slf4j libraries for logging messages.  How can these messages be logged to our BE application log file?

Issue/Introduction

How to bridge the sl4j and log4j logging mechanisms in BE 5.6 and 6.1.

Resolution

Follow the steps below:

1. Disable the default BE logging configuration. In the CDD editor in Studio, go to the 'Collections' tab, and select logConfig'.  In the configuration options, un-check the 'Enable' checkbox.  This will disable the default logging configuration, which you must now replace with a custom logging configuration. Note that a logging configuration is already provided in your BE installation under %BE_HOME%/lib/ext/tpcl/apache/

2. Although you may edit the BE-provided logging configuration in-place, it is recommended that you instead specify the path to your custom logging configuration in your project's CDD file under the 'Cluster' tab. Add the cluster-level property as follows (note the property name and path syntax is different, depending on your BE version):
  • For BE 5.6: log4j.configuration=file:C:/logconfigs/log4j.xml
  • For BE 6.1: log4j.configurationFile=file:///C:/logconfigs/log4j2.xml
3. For BE 5.6, no further configuration is needed, as the necessary slf4j-log4j bridge is already provided in your installation under %BE_HOME%/lib/ext/tpcl/slf4j-log4j12-1.7.28.jar. For BE 6.1, you will need to obtain the updated binding for log4j v2 from Maven Central:

4.  Add the log4j-slf4j-impl-2.0.2.jar to the front of the classpath. You can do this with the 'tibco.env.CUSTOM_EXT_PREPEND_CP' property in your BE engine TRA file:
       
  tibco.env.CUSTOM_EXT_PREPEND_CP=C:/jars/log4j-slf4j-impl-2.0.2.jar

You are now configured to emit slf4j logging messages via log4j.