Listening for Log Messages

There are two ways to listen for log messages. You can either take advantage of the JMX infrastructure and register a notification listener with the LogBroadcasterRuntime MBean, or you can attach a custom log handler (using the JDK 1.4 Logging API) to the server’s Logger directly using a startup class. Using the Logging API is simpler and lets you benefit from other features of the API, such as filtering and message formatting.

JMX Listeners

WebLogic distributes log messages as JMX notifications. Thus, writing an application that listens and responds to log events is no different from writing any other notification listener, which we covered in Chapter 20. As Figure 21-1 illustrates, each server hosts a log broadcaster. This is implemented by the LogBroadcasterRuntime MBean. The following command retrieves the name of the LogBroadcasterRuntime MBean on a Managed Server:

java weblogic.Admin -url t3://servera.x:7001/ -username system -password pssst 
     GET -pretty -type LogBroadcasterRuntime

In this case, the name of the MBean on ServerA is:

myClusterDomain:Location=ServerA,Name=TheLogBroadcaster,Type=LogBroadcasterRuntime

You can use the MBean’s name to register a NotificationListener with the LogBroadcasterRuntime MBean:

WebLogicObjectName name = new WebLogicObjectName("TheLogBroadcaster", "LogBroadcasterRuntime", "myClusterDomain", "ServerA"); MyLogListener mll = new MyLogListener( ); ah.getMBeanServer( ).addNotificationListener(name, mll, null /*no filter*/, ...

Get WebLogic: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.