FileDocCategorySizeDatePackage
LogMgmtEventsNotificationListener.javaAPI DocGlassfish v2 API5598Fri May 04 22:35:04 BST 2007com.sun.enterprise.management.selfmanagement

LogMgmtEventsNotificationListener

public final class LogMgmtEventsNotificationListener extends Object implements NotificationListener
author
Harpreet Singh

Fields Summary
private static final Logger
_logger
Logger for self management service
private static final com.sun.enterprise.util.i18n.StringManager
localStrings
Local Strings manager for the class
public static final String
RECORD_EVENT_KEY
Is logging turned on for this particular even. Key corresponds to the record-event from the event element in domain xml
public static final String
RECORD_LOG_LEVEL_KEY
public static final String
EVENT_TYPE_KEY
public static final String
EVENT_DESCRIPTION_KEY
Constructors Summary
private LogMgmtEventsNotificationListener()
Creates a new instance of LogMgmtEventsNotificationListener


           
      
        // do Nothing
    
Methods Summary
public static com.sun.enterprise.management.selfmanagement.LogMgmtEventsNotificationListenergetInstance()

        return new LogMgmtEventsNotificationListener ();
    
public voidhandleNotification(javax.management.Notification notification, java.lang.Object handback)

        
        Map<String, String> property =
                (Map<String, String>) handback;
        
        if (property == null)
            return;
        
        String recordevent = null;;
        recordevent = (String)property.get(RECORD_EVENT_KEY);
	if (recordevent == null)
	   return;

        boolean recordEvent = false;
        if (recordevent != null){
            recordEvent = Boolean.valueOf(recordevent);
            
            if(recordEvent){
                try{
		    StringBuffer message  = 
			new StringBuffer(localStrings.
				getString("logMgmtEventsNotificationListener.prefix"));

                    String eventType = (String)property.get(EVENT_TYPE_KEY);

		    if (eventType != null){
			message.append (eventType);	
			message.append (":");
		    }
                    String logLevel = (String) property.get(RECORD_LOG_LEVEL_KEY);
	            if(logLevel == null){
			logLevel = Level.FINE.toString();	
		    }
		    message.append (logLevel);
		    message.append (":");
                    Level level = Level.parse(logLevel);

                    String description = (String) property.get(EVENT_DESCRIPTION_KEY);

		    if (description != null){
			message.append (description);
			message.append (":");
		   }
                    _logger.log(level, message.toString());
                } catch (IllegalArgumentException iae) {
                    _logger.log(Level.FINE, "Incorrect Log Level set for event. Cannot log event ", iae);
			iae.printStackTrace();
                } catch (NullPointerException npe){
                    _logger.log(Level.FINE, "Incorrect Log Level set for event. Cannot log event ", npe);
			npe.printStackTrace();
		}
            }
        }