org.jboss.logging
Class Log4jService

java.lang.Object
  |
  +--org.jboss.logging.Log4jService
All Implemented Interfaces:
java.util.EventListener, Log4jServiceMBean, javax.management.MBeanRegistration, javax.management.NotificationListener

public class Log4jService
extends java.lang.Object
implements Log4jServiceMBean, javax.management.NotificationListener, javax.management.MBeanRegistration

This is a JMX MBean that provides two features: 1., It initalizes the log4j framework from the log4j properties format file specified by the ConfigurationPath attribute to that the log4j may be used by JBoss components. 2., It collects JMX notification events fired by the "service=Log" mbean and logs the msgs to the log4j root Category. This allows the Log4jService to replace all other JBoss logging services like ConsoleLogging and FileLogging.

Version:
$Revision: 1.2.2.1 $
Author:
Fulco Muriglio, Scott_Stark@displayscape.com

Fields inherited from interface org.jboss.logging.Log4jServiceMBean
OBJECT_NAME
 
Constructor Summary
Log4jService()
           
Log4jService(java.lang.String path)
           
Log4jService(java.lang.String path, int refreshPeriod)
           
 
Method Summary
 java.lang.String getConfigurationPath()
          Get the log4j.properties format config file path
 boolean getRefreshFlag()
          Get the refresh flag.
 void handleNotification(javax.management.Notification n, java.lang.Object handback)
          This method recevies JMX notification events posted via a Logger instances fireNotification method and logs the msg through the log4j root Category.
 void postDeregister()
           
 void postRegister(java.lang.Boolean b)
           
 void preDeregister()
           
 javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
          Initializes the MBean by registering as a addNotificationListener of the Log service and then invokes start() to configure the log4j framework.
 void setConfigurationPath(java.lang.String path)
          Set the log4j.properties format config file path
 void setRefreshFlag(boolean flag)
          Set the refresh flag.
 void start()
          Configures the log4j framework using the current service properties and sets the service category to the log4j root Category.
 void stop()
          Stops the log4j framework by calling the Category.shutdown() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4jService

public Log4jService()

Log4jService

public Log4jService(java.lang.String path)

Log4jService

public Log4jService(java.lang.String path,
                    int refreshPeriod)
Parameters:
path, - the path to the log4j.properties format file
refreshPeriod, - the refreshPeriod in seconds to wait between each check.
Method Detail

getConfigurationPath

public java.lang.String getConfigurationPath()
Get the log4j.properties format config file path
Specified by:
getConfigurationPath in interface Log4jServiceMBean

setConfigurationPath

public void setConfigurationPath(java.lang.String path)
Set the log4j.properties format config file path
Specified by:
setConfigurationPath in interface Log4jServiceMBean

getRefreshFlag

public boolean getRefreshFlag()
Get the refresh flag. This determines if the log4j.properties file is reloaded every refreshPeriod seconds or not.
Specified by:
getRefreshFlag in interface Log4jServiceMBean

setRefreshFlag

public void setRefreshFlag(boolean flag)
Set the refresh flag. This determines if the log4j.properties file is reloaded every refreshPeriod seconds or not.
Specified by:
setRefreshFlag in interface Log4jServiceMBean

start

public void start()
           throws java.lang.Exception
Configures the log4j framework using the current service properties and sets the service category to the log4j root Category. This method throws a FileNotFoundException exception if the current configurationPath cannot be located to avoid interaction problems between the log4j framework and the JBoss ConsoleLogging service.
Specified by:
start in interface Log4jServiceMBean

stop

public void stop()
Stops the log4j framework by calling the Category.shutdown() method.
Specified by:
stop in interface Log4jServiceMBean
See Also:
Category.shutdown()

handleNotification

public void handleNotification(javax.management.Notification n,
                               java.lang.Object handback)
This method recevies JMX notification events posted via a Logger instances fireNotification method and logs the msg through the log4j root Category.
Specified by:
handleNotification in interface javax.management.NotificationListener
Parameters:
n, - the log event. This provides the log source as n.getUserData(), the log msg as n.getMessage(), and the type of message from n.getType().
See Also:
Logger.fireNotification(String, Object, String)

preRegister

public javax.management.ObjectName preRegister(javax.management.MBeanServer server,
                                               javax.management.ObjectName name)
                                        throws java.lang.Exception
Initializes the MBean by registering as a addNotificationListener of the Log service and then invokes start() to configure the log4j framework.
Specified by:
preRegister in interface javax.management.MBeanRegistration
Returns:
the name of this mbean.

postRegister

public void postRegister(java.lang.Boolean b)
Specified by:
postRegister in interface javax.management.MBeanRegistration

preDeregister

public void preDeregister()
Specified by:
preDeregister in interface javax.management.MBeanRegistration

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface javax.management.MBeanRegistration


Copyright © 2000 The JBoss Organization. All Rights Reserved.