@ Override public Logger getLogger ( String name ) { // get the logger from the super impl Logger logger = super . getLogger ( name ) ; // At this point we don't know which concrete class to use until the // ras/logging provider is initialized enough to provide a // wsLogger class if ( wsLogger == null ) { return logger ; } // The Java Logging (JSR47) spec requires that the method, // LogManager.getLogManager().getLogger(...) returns null if the logger // with the passed in name does not exist. However, the method // Logger.getLogger(...) // calls this method in order to create a new Logger object. In WAS, we // always want the call to Logger.getLogger(...) to return an instance // of WsLogger. If this method returns null to it (as the spec requires), // then Logger.getLogger() would return an instance of java.util.logging.Logger // rather than our WsLogger. // To account for this "issue", we need to return null when a customer // calls this method and passes in a non-existent logger name, but must // create a new WsLogger when Logger.getLogger() calls this method. As // such, the following code will get the current thread's stack trace // and look for a pattern like: // ... // at com.ibm.ws.bootstrap.WsLogManager.getLogger ... // at java.util.logging.Logger.getLogger ... // ... // If it identifies this pattern in the stacktrace, this method will // create a new logger. If not, it will return null. if ( logger == null ) { boolean createNewLogger = false ; boolean foundCaller = false ; Exception ex = new Exception ( ) ; StackTraceElement [ ] ste = ex . getStackTrace ( ) ; Class < ? > caller = null ; int i = 0 ; while ( ! foundCaller && i < ste . length ) { StackTraceElement s = ste [ i ++ ] ; // A) look for com.ibm.ws.bootstrap.WsLogManager.getLogger if ( s . getClassName ( ) . equals ( CLASS_NAME ) && s . getMethodName ( ) . equals ( "getLogger" ) ) { // B) java.util.logging.Logger.getLogger while ( ! foundCaller && i < ste . length ) { s = ste [ i ++ ] ; if ( s . getClassName ( ) . equals ( "java.util.logging.Logger" ) && s . getMethodName ( ) . equals ( "getLogger" ) ) { createNewLogger = true ; } else if ( createNewLogger ) { caller = StackFinderSingleton . instance . getCaller ( i , s . getClassName ( ) ) ; foundCaller = caller != null ; } } } } if ( createNewLogger ) { try { logger = ( Logger ) wsLogger . newInstance ( name , caller , null ) ; // constructing the new logger will add the logger to the log manager // See the constructor com.ibm.ws.logging.internal.WsLogger.WsLogger(String, Class<?>, String) // This is pretty unfortunate escaping of 'this' out of the constructor, but may be risky to try and fix that. // Instead add a hack here to double check that another thread did not win in creating and adding the WsLogger instance Logger checkLogger = super . getLogger ( name ) ; if ( checkLogger != null ) { // Simply reassign because checkLogger is for sure the one that got added. // Not really sure what it would mean if null was returned from super.getLogger, but do nothing in that case logger = checkLogger ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } } return logger ; }
Returns an instance of WsLogger with specified name . If an instance with specified name does not exist it will be created .