1 23 24 package com.sun.enterprise.corba.ee.internal.util; 25 26 import java.util.logging.Logger ; 27 28 import java.lang.reflect.Method ; 29 import java.lang.reflect.Field ; 30 31 34 import java.util.MissingResourceException ; 35 36 public class LogWrap { 37 38 public static Logger logger; 39 40 private static final String LOGDOMAINS_CLASS_NAME = 41 "com.sun.logging.LogDomains"; 42 private static final String GET_LOGGER_METHOD_NAME = "getLogger"; 43 44 private static final String ORB_LOGGER_FIELD_NAME = "CORBA_LOGGER"; 45 private static final String ORB_LOGGER_NAME = 46 "javax.enterprise.resource.corba"; 47 private static final String ORB_LOGGER_RESOURCE_BUNDLE = 48 "com.sun.logging.enterprise.resource.corba.LogStrings"; 49 50 static { 51 try { 52 logger = getLoggerUsingLogDomainsAPI(); 53 if (logger == null) { 54 System.out.println("Could not initialize LogDomains logger"); 55 } 56 } catch (Exception ex) { 57 System.out.println("Could not initialize LogDomains logger"); 58 } 59 60 if (logger == null) { 61 try { 62 logger = getLoggerUsingJavaLoggingAPI(); 63 if (logger == null) { 64 System.out.println("Could not initialize JDK logger"); 65 } 66 } catch (Exception ex) { 67 System.out.println("Could not initialize JDK logger"); 68 ex.printStackTrace(); 69 } 70 } 71 } 72 73 private static Logger getLoggerUsingLogDomainsAPI() throws Exception { 74 Class logDomainsClass = Class.forName(LOGDOMAINS_CLASS_NAME); 75 76 Class [] parameterClasses = new Class [1]; 77 parameterClasses[0] = String .class; 78 Method getLoggerMethod = logDomainsClass.getDeclaredMethod( 79 GET_LOGGER_METHOD_NAME, parameterClasses); 80 81 Field orbLoggerNameField = logDomainsClass.getDeclaredField( 82 ORB_LOGGER_FIELD_NAME); 83 String orbLoggerName = (String )orbLoggerNameField.get(null); 84 85 Object [] parameters = new Object [1]; 86 parameters[0] = orbLoggerName; 87 Logger lgr = (Logger )getLoggerMethod.invoke(null, parameters); 88 89 return lgr; 90 } 91 92 private static Logger getLoggerUsingJavaLoggingAPI() throws Exception { 93 Logger lgr = Logger.getLogger(ORB_LOGGER_NAME, ORB_LOGGER_RESOURCE_BUNDLE); 94 95 return lgr; 96 } 97 98 } 99 | Popular Tags |