ensure logging can be setup property in tomee embedded

Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/1b3ddcf6
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/1b3ddcf6
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/1b3ddcf6

Branch: refs/heads/master
Commit: 1b3ddcf63b46990ffbdc862922b9a322c9e8f884
Parents: fa939e0
Author: rmannibucau <rmannibu...@apache.org>
Authored: Thu Sep 29 12:15:33 2016 +0200
Committer: rmannibucau <rmannibu...@apache.org>
Committed: Thu Sep 29 12:15:33 2016 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/openejb/util/Logger.java    |  8 ++++++--
 .../embedded/TomEEEmbeddedApplicationRunner.java     |  5 +++--
 .../org/apache/tomee/jul/formatter/log/TomEELog.java | 15 ++++++++++-----
 3 files changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/1b3ddcf6/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java 
b/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
index 01aa284..40f422b 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/Logger.java
@@ -26,16 +26,16 @@ import java.io.Serializable;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.Properties;
 import java.util.ResourceBundle;
-import java.util.Locale;
 
 public class Logger {
     private static final String SUFFIX = ".Messages";
     private static final String OPENEJB = "org.apache.tomee";
-    private static LogStreamFactory logStreamFactory;
+    private static LogStreamFactory logStreamFactory; // TODO: make it 
resettable
 
     // don't return the instance since it needs to stay private but export 
which one is used to allow integration with other libs (as tomcat ;))
     @SuppressWarnings("UnusedDeclaration")
@@ -46,6 +46,10 @@ public class Logger {
         return logStreamFactory.getClass().getName();
     }
 
+    public static LogStreamFactory unsafeDelegateClass() {
+        return logStreamFactory;
+    }
+
     public static synchronized void configure() {
         configure(System.getProperties());
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/1b3ddcf6/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
 
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
index a06b8c2..91755af 100644
--- 
a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
+++ 
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/TomEEEmbeddedApplicationRunner.java
@@ -193,7 +193,7 @@ public class TomEEEmbeddedApplicationRunner implements 
AutoCloseable {
                 urls.add(f.toURI().toURL());
             }
         } else {
-            urls = new 
DeploymentsResolver.ClasspathSearcher().loadUrls(Thread.currentThread().getContextClassLoader()).getUrls();
+            urls = null;
         }
 
         final WebResource resources = 
appClass.getAnnotation(WebResource.class);
@@ -218,7 +218,8 @@ public class TomEEEmbeddedApplicationRunner implements 
AutoCloseable {
         final Container container = new Container(configuration)
                 .deploy(new Container.DeploymentRequest(
                         context,
-                        urls,
+                        // call ClasspathSearcher that lazily since container 
needs to be started to not preload logging
+                        urls == null ? new 
DeploymentsResolver.ClasspathSearcher().loadUrls(Thread.currentThread().getContextClassLoader()).getUrls()
 : urls,
                         webResource != null ? new File(webResource) : null,
                         true,
                         null,

http://git-wip-us.apache.org/repos/asf/tomee/blob/1b3ddcf6/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/TomEELog.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/TomEELog.java
 
b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/TomEELog.java
index bd1d102..9cf390d 100644
--- 
a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/TomEELog.java
+++ 
b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/TomEELog.java
@@ -35,13 +35,18 @@ public class TomEELog implements Log {
             try {
                 final ClassLoader tccl = thread.getContextClassLoader();
                 final Class<?> systemInstance = 
tccl.loadClass("org.apache.openejb.loader.SystemInstance");
-                if 
(!Boolean.class.cast(systemInstance.getMethod("isInitialized").invoke(null))) {
-                    return;
+                if 
(!Boolean.class.cast(systemInstance.getMethod("isInitialized").invoke(null))) { 
// check if Logger was forced
+                    final Class<?> logger = 
tccl.loadClass("org.apache.openejb.util.Logger");
+                    final Method m = 
logger.getDeclaredMethod("unsafeDelegateClass");
+                    loggerClazz = m.invoke(null).getClass().getName();
+                }
+
+                if (loggerClazz == null) {
+                    final Class<?> logger = 
tccl.loadClass("org.apache.openejb.util.Logger");
+                    final Method m = logger.getDeclaredMethod("delegateClass");
+                    loggerClazz = (String) m.invoke(null);
                 }
 
-                final Class<?> logger = 
tccl.loadClass("org.apache.openejb.util.Logger");
-                final Method m = logger.getDeclaredMethod("delegateClass");
-                loggerClazz = (String) m.invoke(null);
                 switch (loggerClazz) {
                     case "org.apache.openejb.util.Log4j2LogStreamFactory":
                     case "org.apache.openejb.util.Log4jLogStreamFactory":

Reply via email to