In IBM® WebSphere® Message Broker, the Trace node is used for logging, but it has two limitations:
- It does not have configurable log levels.
- It is not extensible to other targets.
The well-known open-source Log4j logging framework from Apache Software Foundation solves those two limitations for Java-base applications. The WebSphere Message Broker IAM3 SupportPac provides a node that can be used by message flows in order to address all targets reachable by Log4j and configure log levels at runtime. To change the logging, you do not have to restart the broker or message flow, and the change is effective without delay.
Log4j is written in Java and has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages. Log4j enables you to control logging behavior by editing a configuration file without touching the application code, so that logging statements can remain in shipped code without harming performance. Another feature of Log4j is inheritance in a logger hierarchy, which reduces the volume of logged output and the performance costs of logging. Log4j lets you direct log output to a file, an OutputStream, a java.io.Writer, a remote Log4j server, and to other output targets.
You can use Log4j to insert logging points into the code to make visible key progress points. For example:
- When a message is accepted at an Input node of any protocol, insert an INFO log point.
- After a message is put to an Output node of any protocol, insert an INFO log point.
- If a message is split into several parts, insert an INFO log point after the node performing the split.
- If you use a service call mechanism such as an HTTPRequest node or an MQRequest node, insert INFO log points to show that a request was sent and a response was received.
- If you use resend logic, insert WARNING log points, unless you are using a framework that already contains such logging.
Log4j severity levels
As shown below, four severity levels are defined in the Log4j logging framework and used to identify and tag different events so that you can apply filtering. You need to assign an appropriate log level for each message that is to be logged.
- ERROR -- Use when an application encounters a problem from which it cannot recover. Failing to process a message can be classified as an ERROR.
- WARN -- Use to indicate that a non-critical error has occurred. For example, a retransmission loop has been started, or a table has missing data but the integration can recover.
- INFO -- The "normal" severity level -- use for important events in an integration, such as message received, message committed to a queue, or the result of a routing decision.
- DEBUG -- Use for logging information for debugging purposes -- usually during development. The DEBUG level is filtered in all environments except in the development environment.
- The field
Environment.Variables.Log4j.LogTexttakes precedence if it has a value when the Log4j node is reached.
- The XPath and ESQL styles always wrap the result of an expression with the
string()function, and no other XPath function is supported. If you want to output additional information, use the XML or XESQL styles.
- The name of the flow is mapped to the thread property for Log4j using the Log4j node. In ESQL, you must provide this name explicitly, because it is not accessible because of ESQL to Java mappings.
Configuring the Log4j node in WebSphere Message Broker
Installing the Log4j node in WebSphere Message Broker Toolkit
- Download the WebSphere Message Broker IAM3 SupportPac: Node for Log4j.
- From the downloaded zip file, extract
Log4jLoggingPlugin_v1.1 zipinto the Plug-in folder, which for the V7 Toolkit is
C:\Program Files\IBM\WMBT700\plugins. You can see the extracted folder in Figure1:
Figure 1. Copy Log4j Logging Plug-in folder in Plug-in folder.
- Restart the Toolkit.
Installing the Log4j node in WebSphere Message Broker
- To Install the plug-in in the WebSphere Message Broker runtime, copy the three files
Log4jLoggingNode_v1.1.1.jar, jakarta-oro-2.0.4.jar, and
MQSI\Shared Classesfolder. The default path is
C:\Documents and Settings\All Users\Application Data\IBM\MQSI\shared-classes, but the path depends on your installation setup.
Figure 2. Copy three files to Shared Classes Folder
Log4jLoggingNode_v1.1.1to the folder
C:\Program Files\IBM\MQSI\7.0\jplugin, as shown below:
Figure 3. Log4jLoggingNode_v1.1.1 file in jplugin Folder
- Restart the WebSphere Message Broker runtime.
Using the Log4J node in a message flow
To use the Log4J node, you need to populate an XML file with the location of the log file and the logging levels desired. This XML file is the configuration input for the broker at runtime.
By default, the filename is
brokerlog.xml, and this file along with
brokerlog.dtd must be present in the broker CLASSPATH, as shown below.
The Log4J node also requires some initialization before you use it.
Listing 1. ESQL code in Compute node
CREATE FUNCTION initLog4j( IN CONFIG_FILE_NAME CHARACTER ) RETURNS BOOLEAN LANGUAGE JAVA EXTERNAL NAME "com.ibm.broker.IAM3.Log4jNode.initLog4j"; CREATE FUNCTION log4j_1_1( IN COMPONENT_NAME CHARACTER, IN LOGGER_NAME CHARACTER, IN LEVEL CHARACTER, IN TEXT CHARACTER ) RETURNS BOOLEAN LANGUAGE JAVA EXTERNAL NAME "com.ibm.broker.IAM3.Log4jNode.log"; CREATE PROCEDURE Initialize_Log4j() BEGIN DECLARE rc BOOLEAN; IF (SIMPOC_Log4j_Initialized.valid = NULL) THEN CALL initLog4j('brokerlog.xml') INTO rc; IF ( rc = FALSE ) THEN THROW USER EXCEPTION MESSAGE 5560 VALUES ('Error Initializing log4j'); END IF; SET SIMPOC_Log4j_Initialized = TRUE; CALL log4j_1_1(SQL.MessageFlowLabel, 'default', 'WARN', 'initLog4j() completed initialization of log4J env.' ) INTO rc; END IF; END;
To call the function, use
CALL Initialize_Log4j();. The data to be logged must be present in the environment before control reaches the Log4j node:
SET Environment.Variables.Log4j.LogText ="USER DEFINED LOG";.
You can also log the information by writing an Xpath expression to extract data from the incoming message.
As shown below, this node will log the data in the
Figure 4. Message flow MF_LOG4J_1.msgflow
This article showed you how to configure and implement the Log4j node in WebSphere Message Broker, in order to enable logging at runtime without modifying the application code. The article also explained the pros and cons of using a Log4j node in a message flow. Logging should be implemented in each message flow to show its operation.
- WebSphere Message Broker resources
- IAM3: WebSphere Message Broker Log4j node
Download this SupportPac in order to implement the Log4j logging framework in your Message Broker message flows.
- Apache Log4j 1.2
The Log4j logging library for Java from the Apache Software Foundation.
- WebSphere Message Broker V8 information center
A single Web portal to all WebSphere MQ V7 documentation, with conceptual, task, and reference information on installing, configuring, and using WebSphere Message Broker V8.
- WebSphere Message Broker product page
Product descriptions, product news, training information, support information, and more.
- Download free trial version of WebSphere Message Broker
WebSphere Message Broker is an ESB built for universal connectivity and transformation in heterogeneous IT environments. It distributes information and data generated by business events in real time to people, applications, and devices throughout your extended enterprise and beyond.
- WebSphere Message Broker documentation library
WebSphere Message Broker specifications and manuals.
- WebSphere Message Broker forum
Get answers to technical questions and share your expertise with other WebSphere Message Broker users.
- WebSphere Message Broker support page
A searchable database of support problems and their solutions, plus downloads, fixes, and problem tracking.
- IBM Training course: WebSphere Message Broker V8 Development
This course from IBM Training shows you how to use the components of the WebSphere Message Broker development and runtime environments to develop and troubleshoot message flows that use ESQL, Java, and PHP to transform messages.
- IAM3: WebSphere Message Broker Log4j node
- WebSphere resources
- developerWorks WebSphere
Technical information and resources for developers who use WebSphere products. developerWorks WebSphere provides product downloads, how-to information, support resources, and a free technical library of more than 2000 technical articles, tutorials, best practices, IBM Redbooks, and online product manuals.
- developerWorks WebSphere application integration developer resources
How-to articles, downloads, tutorials, education, product info, and other resources to help you build WebSphere application integration and business integration solutions.
- Most popular WebSphere trial downloads
No-charge trial downloads for key WebSphere products.
- WebSphere forums
Product-specific forums where you can get answers to your technical questions and share your expertise with other WebSphere users.
- WebSphere demos
Download and watch these self-running demos, and learn how WebSphere products can provide business advantage for your company.
- WebSphere-related articles on developerWorks
Over 3000 edited and categorized articles on WebSphere and related technologies by top practitioners and consultants inside and outside IBM. Search for what you need.
- developerWorks WebSphere weekly newsletter
The developerWorks newsletter gives you the latest articles and information only on those topics that interest you. In addition to WebSphere, you can select from Java, Linux, Open source, Rational, SOA, Web services, and other topics. Subscribe now and design your custom mailing.
- WebSphere-related books from IBM Press
Convenient online ordering through Barnes & Noble.
- WebSphere-related events
Conferences, trade shows, Webcasts, and other events around the world of interest to WebSphere developers.
- developerWorks WebSphere
- developerWorks resources
- Trial downloads for IBM software products
No-charge trial downloads for selected IBM® DB2®, Lotus®, Rational®, Tivoli®, and WebSphere® products.
- developerWorks business process management developer resources
BPM how-to articles, downloads, tutorials, education, product info, and other resources to help you model, assemble, deploy, and manage business processes.
- developerWorks blogs
Join a conversation with developerWorks users and authors, and IBM editors and developers.
- developerWorks tech briefings
Free technical sessions by IBM experts to accelerate your learning curve and help you succeed in your most challenging software projects. Sessions range from one-hour virtual briefings to half-day and full-day live sessions in cities worldwide.
- developerWorks podcasts
Listen to interesting and offbeat interviews and discussions with software innovators.
- developerWorks on Twitter
Check out recent Twitter messages and URLs.
- IBM Education Assistant
A collection of multimedia educational modules that will help you better understand IBM software products and use them more effectively to meet your business requirements.
- Trial downloads for IBM software products
Dig deeper into WebSphere on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Keep up with the best and latest technical info to help you tackle your development challenges.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.