public static < T > T getMessageLogger ( final Class < T > type , final String category , final Locale locale ) { return doPrivileged ( new PrivilegedAction < T > ( ) { public T run ( ) { String language = locale . getLanguage ( ) ; String country = locale . getCountry ( ) ; String variant = locale . getVariant ( ) ; Class < ? extends T > loggerClass = null ; final ClassLoader classLoader = type . getClassLoader ( ) ; final String typeName = type . getName ( ) ; if ( variant != null && variant . length ( ) > 0 ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , language , country , variant ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { // ignore } if ( loggerClass == null && country != null && country . length ( ) > 0 ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , language , country , null ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { // ignore } if ( loggerClass == null && language != null && language . length ( ) > 0 ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , language , null , null ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { // ignore } if ( loggerClass == null ) try { loggerClass = Class . forName ( join ( typeName , "$logger" , null , null , null ) , true , classLoader ) . asSubclass ( type ) ; } catch ( ClassNotFoundException e ) { throw new IllegalArgumentException ( "Invalid logger " + type + " (implementation not found in " + classLoader + ")" ) ; } final Constructor < ? extends T > constructor ; try { constructor = loggerClass . getConstructor ( Logger . class ) ; } catch ( NoSuchMethodException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " has no matching constructor" ) ; } try { return constructor . newInstance ( Logger . getLogger ( category ) ) ; } catch ( InstantiationException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " could not be instantiated" , e ) ; } catch ( IllegalAccessException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " could not be instantiated" , e ) ; } catch ( InvocationTargetException e ) { throw new IllegalArgumentException ( "Logger implementation " + loggerClass + " could not be instantiated" , e . getCause ( ) ) ; } } } ) ; }
Get a typed logger which implements the given interface . The given locale will be used for the new logger .