Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2590CD04D for ; Thu, 25 Oct 2012 14:22:14 +0000 (UTC) Received: (qmail 3288 invoked by uid 500); 25 Oct 2012 14:22:13 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 3165 invoked by uid 500); 25 Oct 2012 14:22:13 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 3152 invoked by uid 99); 25 Oct 2012 14:22:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2012 14:22:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2012 14:22:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6F76023888CD; Thu, 25 Oct 2012 14:21:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1402160 - /cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java Date: Thu, 25 Oct 2012 14:21:25 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121025142125.6F76023888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Thu Oct 25 14:21:24 2012 New Revision: 1402160 URL: http://svn.apache.org/viewvc?rev=1402160&view=rev Log: [CXF-4602] Some improvements to the logger creation Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=1402160&r1=1402159&r2=1402160&view=diff ============================================================================== --- cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java (original) +++ cxf/trunk/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java Thu Oct 25 14:21:24 2012 @@ -232,42 +232,60 @@ public final class LogUtils { protected static Logger createLogger(Class cls, String name, String loggerName) { - 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; - } - } + 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); } - } 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 } }