Logging Common Base Events in WAS
The following practices ensure consistent use of Common Base Events within your components, and between your components and WebSphere Application Server components.
Follow these guidelines:
- Use a different logger for each component. Sharing loggers across components gets in the way of associating loggers with component-specific information.
- Associate loggers with event templates that specify source component identification. This association ensures that the source of all events created with the logger is properly identified.
- Use the same template for directly created Common Base Events (events created using the Common Base Event factories) and indirectly created Common Base Events (events created using the Java logging API) within the same component.
- Avoid calling the complete method on Common Base Events until we are finished adding data to the Common Base Event and are ready to log it. This approach ensures any decisions made by the content handler based on data already in the event are made using the final data.
The following sample Logger.properties file entry demonstrates how to associate the com.ibm.componentX logger with the com.ibm.componentX event factory:
com.ibm.componentX.eventfactory=com.ibm.componentXThe following sample code demonstrates the use of the same event factory setting for direct (Part 1) and indirect (Part 2) Common Base Event logging:
<?xml version="1.0" encoding="UTF-8"?> <TemplateEvent> version="1.0.1" xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation="templateEvent.xsd"> <CommonBaseEvent> <sourceComponentId application="My application" component="com.ibm.componentX"/> <extendedDataElements CommonBaseEventname="Sample ExtendedDataElement name" type="string"> <values>Sample ExtendedDataElement value</values> </extendedDataElements> < /CommonBaseEvent> < /TemplateEvent>
Logging with Common Base Event API and the Java logging API Logging Common Base Events in WAS Add logging and tracing to the application