1 23 24 package com.sun.enterprise.server.logging; 25 26 import java.util.logging.ErrorManager ; 27 import java.util.ArrayList ; 28 import java.util.Arrays ; 29 import com.sun.logging.LogDomains; 30 import com.sun.enterprise.server.ServerContext; 31 import com.sun.enterprise.server.ApplicationServer; 32 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 33 import com.sun.enterprise.config.serverbeans.Server; 34 import com.sun.enterprise.config.serverbeans.Config; 35 import com.sun.enterprise.config.serverbeans.ElementProperty; 36 import com.sun.enterprise.config.serverbeans.ModuleLogLevels; 37 import com.sun.enterprise.config.serverbeans.LogService; 38 39 44 public class ModuleToLoggerNameMapper { 45 46 90 private static Object [][] ModuleAndLoggerTable = { 91 {"admin", new String [] { LogDomains.ADMIN_LOGGER } }, {"classloader", new String [] { LogDomains.LOADER_LOGGER} }, {"cmp", new String [] { LogDomains.CMP_LOGGER} }, 94 {"cmp-container", new String [] { LogDomains.CMP_LOGGER} }, {"configuration", new String [] { LogDomains.CONFIG_LOGGER} }, 96 {"connector", new String [] { LogDomains.RSR_LOGGER} }, 97 {"resource-adapter", new String [] { LogDomains.RSR_LOGGER} }, {"corba", new String [] { LogDomains.CORBA_LOGGER} }, 99 {"deployment", new String [] { LogDomains.DPL_LOGGER} }, 100 {"ejb-container", new String [] { LogDomains.EJB_LOGGER} }, 101 {"javamail", new String [] { LogDomains.JAVAMAIL_LOGGER} }, 102 {"jaxr", new String [] { LogDomains.JAXR_LOGGER} }, 103 {"jaxrpc", new String [] { LogDomains.JAXRPC_LOGGER} }, 104 {"jdo", new String [] { LogDomains.JDO_LOGGER} }, 105 {"jms", new String [] { LogDomains.JMS_LOGGER, "javax.resourceadapter.mqjmsra"} }, 106 {"jta", new String [] { LogDomains.JTA_LOGGER} }, 107 {"jts", new String [] { LogDomains.TRANSACTION_LOGGER} }, 108 {"mdb-container", new String [] { LogDomains.MDB_LOGGER} }, 109 {"naming", new String [] { LogDomains.JNDI_LOGGER} }, 111 {"saaj", new String [] { LogDomains.SAAJ_LOGGER} }, 112 {"security", new String [] { LogDomains.SECURITY_LOGGER} }, 113 {"self-management",new String [] { LogDomains.SELF_MANAGEMENT_LOGGER} }, 114 {"synchronization",new String [] { "javax.ee.enterprise.system.tools.synchronization"} }, 115 {"verifier", new String [] { LogDomains.APPVERIFY_LOGGER} }, 116 {"web-container", new String [] { LogDomains.WEB_LOGGER, 117 "org.apache.catalina", 118 "org.apache.coyote","org.apache.jasper" 119 } }, 120 {"group-management-service", new String [] { LogDomains.GMS_LOGGER} }, 121 {"node-agent", new String [] { "javax.ee.enterprise.system.nodeagent" } }, 122 {"util", new String [] { LogDomains.UTIL_LOGGER } }, 123 {"core", new String [] { LogDomains.CORE_LOGGER} }, 124 {"server", new String [] { LogDomains.SERVER_LOGGER} }, 125 {"root", new String [] { LogDomains.ROOT_LOGGER} } 126 }; 127 128 129 133 public static String getModuleName(String loggerName) { 134 for (int i=0; i<ModuleAndLoggerTable.length; i++) { 135 Object [] dim = ModuleAndLoggerTable[i]; 136 String modName = (String )dim[0]; 137 String [] loggerNames = (String []) dim[1]; 138 for (int j=0; loggerNames!=null && j<loggerNames.length;j++) { 139 String name=loggerNames[j]; 140 if (loggerName.equals(name)) 141 return modName; 142 } 143 } 144 return null; 145 } 146 147 148 153 public static String [] getLoggerNames( String moduleName ) { 154 ArrayList result = new ArrayList (); 155 for (int i=0; i<ModuleAndLoggerTable.length; i++) { 156 Object [] dim = ModuleAndLoggerTable[i]; 157 String modName = (String )dim[0]; 158 String [] loggerNames = (String []) dim[1]; 159 if (loggerNames!=null) { 160 if (moduleName == null) { result.addAll(Arrays.asList(loggerNames) ); 162 } else if (moduleName.equals(modName)) { 163 result.addAll( Arrays.asList(loggerNames) ); 164 break; 165 } 166 } 167 } 168 String [] lNames = new String [ result.size()]; 169 return (String [])result.toArray(lNames); 170 } 171 172 173 177 public static String getMatchedModuleLoggerName(String loggerName) { 178 for (int i=0; i<ModuleAndLoggerTable.length; i++) { 179 Object [] dim = ModuleAndLoggerTable[i]; 180 String [] loggerNames = (String []) dim[1]; 181 for (int j=0; loggerNames!=null && j<loggerNames.length;j++) { 182 String name=loggerNames[j]; 183 if (loggerName.startsWith(name) ) 184 return name; 185 } 186 } 187 188 try { 189 ServerContext sc = ApplicationServer.getServerContext(); 190 if (sc!=null) { 191 Config cfg = ServerBeansFactory.getConfigBean(sc.getConfigContext()); 192 ModuleLogLevels allModulesLogLevels = cfg.getLogService().getModuleLogLevels( ); 193 ElementProperty[] elementProperties = allModulesLogLevels.getElementProperty( ); 194 if( elementProperties != null ) { 195 for( int i = 0; i < elementProperties.length; i++ ) { 196 String name = elementProperties[i].getName(); 197 if( loggerName.startsWith(name)) { 198 return name; 199 } 200 } 201 } 202 } 203 } catch ( Exception e ) { 204 new ErrorManager ().error( "Error In Setting Initial Loglevel", e, 205 ErrorManager.GENERIC_FAILURE ); 206 } 207 return null; 208 } 209 } 210 | Popular Tags |