Author: dkulp Date: Thu Oct 25 14:55:43 2012 New Revision: 1402180 URL: http://svn.apache.org/viewvc?rev=1402180&view=rev Log: Merged revisions 1402164 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........ r1402164 | dkulp | 2012-10-25 10:30:14 -0400 (Thu, 25 Oct 2012) | 10 lines Merged revisions 1402160 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1402160 | dkulp | 2012-10-25 10:21:24 -0400 (Thu, 25 Oct 2012) | 2 lines [CXF-4602] Some improvements to the logger creation ........ ........ Modified: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java Modified: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=1402180&r1=1402179&r2=1402180&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java (original) +++ cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java Thu Oct 25 14:55:43 2012 @@ -228,6 +228,7 @@ public final class LogUtils { protected static Logger createLogger(Class<?> cls, String name, String loggerName) { +<<<<<<< HEAD:common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java if (loggerClass != null) { try { Constructor cns = loggerClass.getConstructor(String.class, String.class); @@ -251,19 +252,62 @@ public final class LogUtils { throw ite; } } +======= + ClassLoader orig = Thread.currentThread().getContextClassLoader(); + ClassLoader n = cls.getClassLoader(); + if (n != null) { + Thread.currentThread().setContextClassLoader(n); + } + try { + if (loggerClass != null) { + try { + Constructor<?> cns = loggerClass.getConstructor(String.class, String.class); + if (name == null) { + try { + return (Logger) cns.newInstance(loggerName, BundleUtils.getBundleName(cls)); + } catch (InvocationTargetException ite) { + if (ite.getTargetException() instanceof MissingResourceException) { + return (Logger) cns.newInstance(loggerName, null); + } else { + throw ite; + } + } + } else { + try { + return (Logger) cns.newInstance(loggerName, BundleUtils.getBundleName(cls, name)); + } catch (InvocationTargetException ite) { + if (ite.getTargetException() instanceof MissingResourceException) { + throw (MissingResourceException)ite.getTargetException(); + } else { + throw ite; + } + } + } + } catch (Exception e) { + throw new RuntimeException(e); +>>>>>>> bb4cfa6... Merged revisions 1402160 via git cherry-pick from:api/src/main/java/org/apache/cxf/common/logging/LogUtils.java } - } catch (Exception e) { - throw new RuntimeException(e); } - } - if (name == null) { - try { - return Logger.getLogger(loggerName, BundleUtils.getBundleName(cls)); //NOPMD - } catch (MissingResourceException rex) { - return Logger.getLogger(loggerName, null); //NOPMD + if (name == null) { + ResourceBundle b = null; + try { + //grab the bundle prior to the call to Logger.getLogger(...) so the + //ResourceBundle can be loaded outside the big sync block that getLogger really is + b = BundleUtils.getBundle(cls); + b.getLocale(); + return Logger.getLogger(loggerName, BundleUtils.getBundleName(cls)); //NOPMD + } catch (MissingResourceException rex) { + return Logger.getLogger(loggerName); //NOPMD + } finally { + b = null; + } + } else { + return Logger.getLogger(loggerName, BundleUtils.getBundleName(cls, name)); //NOPMD + } + } finally { + if (n != orig) { + Thread.currentThread().setContextClassLoader(orig); } - } else { - return Logger.getLogger(loggerName, BundleUtils.getBundleName(cls, name)); //NOPMD } }
