Logging with Common Base Event API and the Java logging API
In cases where the events that are generated by the Java logging API are insufficient to describe the event that needs capturing, we can create Common Base Events with the Common Base Event factory APIs.
When creating a Common Base Event, we can add data to the Common Base Event before it is logged. The following diagram illustrates how application code can create and log Common Base Events:
WebSphere Application Server is configured to use an event factory that automatically populates WebSphere Application Server-specific information into the Common Base Events that it generates. In general, it is good practice to create events using the WAS default Common Base Event factory because this approach ensures consistency of Common Base Event content across events. However, we can create and use other Common Base Event factories.
Common Base Events are initiated and logged in the following sequence:
- Application code invokes the createCommonBaseEvent method on the EventFactory class to create a CommonBaseEvent.
- Application code wraps CommonBaseEvent event in a CommonBaseEventLogRecord record, and adds event-specific data.
- Application code calls the CommonBaseEvent event complete method.
- The CommonBaseEvent event invokes the ContentHandler completeEvent method.
- The ContentHandler handler adds XML template data to the CommonBaseEvent event. Not all ContentHandler handlers support templates.
- The ContentHandler handler adds runtime data to the CommonBaseEvent event.
- Application code passes the CommonBaseEventLogRecord record to the logger using the Logger.log method.
- Logger passes CommonBaseEventLogRecord record to Handlers.
- Handlers format data and write to the output device.
- We can use the default Common Base Event factory to generate content. Read Generate Common Base Event content with the default event factory for more information.
- If we do not wish to use the default event factory, we can create custom content handlers and event factories.
- Create a custom factory home. Read Create custom Common Base Event factory homes.
- Create a custom content handler. Read Create custom Common Base Event content handlers.
Results
After completing all the previous steps you will have a Common Base event based on the configuration settings.
Subtopics
- Generate Common Base Event content with the default event factory
A default Common Base Event content handler populates Common Base Events with WAS runtime information. This content handler can also use a Common Base Event template to populate Common Base Events.
- Common Base Event content handler
Content handlers populate data into Common Base Events when the Common Base Event complete method is invoked. We can associate content handlers with Common Base Event templates, which provide default information to transfer into each Common Base Event.
- Create custom Common Base Event content handlers
Create a custom Common Base Event content handler or template to automate configuration or values for specific events.
- Common Base Event factory home
Event Factory homes provide Event Factory instantiation based on a unique factory name.
- Create custom Common Base Event factory homes
Use custom Common Base Event factory homes to control configuration and implementation of unique event factories.
- Common Base Event factory context
The event factory context provides a service to look up event factory homes. Retrieve the event factory context using a call to the EventFactoryContext.getInstance method.
- Common Base Event factory
Use event factories to create Common Base Events and complete event properties with associated content handlers.
java.util.logging -- Java logging programming interface Logger.properties file