1 23 24 29 30 package com.sun.enterprise.management.selfmanagement; 31 32 import java.util.Map ; 33 import javax.management.Notification ; 34 import javax.management.NotificationListener ; 35 import java.util.logging.Logger ; 36 import java.util.logging.Level ; 37 import com.sun.enterprise.config.serverbeans.ServerTags; 38 import com.sun.logging.LogDomains; 39 import com.sun.enterprise.util.i18n.StringManager; 40 44 public class LogMgmtEventsNotificationListener implements NotificationListener { 45 46 47 private static Logger _logger = null; 48 49 50 private static StringManager localStrings = null; 51 52 static { 53 _logger = LogDomains.getLogger(LogDomains.SELF_MANAGEMENT_LOGGER); 54 localStrings = StringManager.getManager(LogMgmtEventsNotificationListener.class); 55 } 56 57 58 62 public static final String RECORD_EVENT_KEY = ServerTags.RECORD_EVENT; 63 64 69 public static final String RECORD_LOG_LEVEL_KEY = ServerTags.LEVEL; 70 71 public static final String EVENT_TYPE_KEY = ServerTags.TYPE; 72 73 public static final String EVENT_DESCRIPTION_KEY = ServerTags.DESCRIPTION; 74 75 76 private LogMgmtEventsNotificationListener() { 77 } 79 80 public static LogMgmtEventsNotificationListener getInstance (){ 81 return new LogMgmtEventsNotificationListener (); 82 } 83 public void handleNotification(Notification notification, Object handback) { 84 85 Map <String , String > property = 86 (Map <String , String >) handback; 87 88 if (property == null) 89 return; 90 91 String recordevent = null;; 92 recordevent = (String )property.get(RECORD_EVENT_KEY); 93 if (recordevent == null) 94 return; 95 96 boolean recordEvent = false; 97 if (recordevent != null){ 98 recordEvent = Boolean.valueOf(recordevent); 99 100 if(recordEvent){ 101 try{ 102 StringBuffer message = 103 new StringBuffer (localStrings. 104 getString("logMgmtEventsNotificationListener.prefix")); 105 106 String eventType = (String )property.get(EVENT_TYPE_KEY); 107 108 if (eventType != null){ 109 message.append (eventType); 110 message.append (":"); 111 } 112 String logLevel = (String ) property.get(RECORD_LOG_LEVEL_KEY); 113 if(logLevel == null){ 114 logLevel = Level.FINE.toString(); 115 } 116 message.append (logLevel); 117 message.append (":"); 118 Level level = Level.parse(logLevel); 119 120 String description = (String ) property.get(EVENT_DESCRIPTION_KEY); 121 122 if (description != null){ 123 message.append (description); 124 message.append (":"); 125 } 126 _logger.log(level, message.toString()); 127 } catch (IllegalArgumentException iae) { 128 _logger.log(Level.FINE, "Incorrect Log Level set for event. Cannot log event ", iae); 129 iae.printStackTrace(); 130 } catch (NullPointerException npe){ 131 _logger.log(Level.FINE, "Incorrect Log Level set for event. Cannot log event ", npe); 132 npe.printStackTrace(); 133 } 134 } 135 } 136 } 137 } 138 139 | Popular Tags |