Author: dkulp
Date: Thu Oct 25 14:30:14 2012
New Revision: 1402164
URL: http://svn.apache.org/viewvc?rev=1402164&view=rev
Log:
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.6.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
Modified:
cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=1402164&r1=1402163&r2=1402164&view=diff
==============================================================================
---
cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
(original)
+++
cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
Thu Oct 25 14:30:14 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
}
}