tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1239288 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb: openjpa/ openjpa/JULOpenJPALog.java openjpa/JULOpenJPALogFactory.java util/JuliLogStreamFactory.java
Date Wed, 01 Feb 2012 19:51:29 GMT
Author: rmannibucau
Date: Wed Feb  1 19:51:28 2012
New Revision: 1239288

URL: http://svn.apache.org/viewvc?rev=1239288&view=rev
Log:
managing openjpa log in embedded mode

Added:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALog.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALogFactory.java
Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java

Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALog.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALog.java?rev=1239288&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALog.java
(added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALog.java
Wed Feb  1 19:51:28 2012
@@ -0,0 +1,94 @@
+package org.apache.openejb.openjpa;
+
+import org.apache.openejb.util.JuliLogStreamFactory;
+import org.apache.openjpa.lib.log.Log;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class JULOpenJPALog  implements Log {
+    private final Logger logger;
+
+    public JULOpenJPALog(final String channel) {
+        logger = Logger.getLogger(channel);
+        if (logger.getHandlers().length == 0) {
+            logger.addHandler(new JuliLogStreamFactory.OpenEJBSimpleLayoutHandler());
+            logger.setUseParentHandlers(false);
+        }
+    }
+
+    @Override
+    public boolean isTraceEnabled() {
+        return logger.isLoggable(Level.FINEST);
+    }
+
+    @Override
+    public boolean isInfoEnabled() {
+        return logger.isLoggable(Level.INFO);
+    }
+
+    @Override
+    public boolean isWarnEnabled() {
+        return logger.isLoggable(Level.WARNING);
+    }
+
+    @Override
+    public boolean isErrorEnabled() {
+        return logger.isLoggable(Level.SEVERE);
+    }
+
+    @Override
+    public boolean isFatalEnabled() {
+        return logger.isLoggable(Level.SEVERE);
+    }
+
+    @Override
+    public void trace(Object o) {
+        logger.finest(o.toString());
+    }
+
+    @Override
+    public void trace(Object o, Throwable t) {
+        logger.log(Level.FINEST, o.toString(), t);
+    }
+
+    @Override
+    public void info(Object o) {
+        logger.info(o.toString());
+    }
+
+    @Override
+    public void info(Object o, Throwable t) {
+        logger.log(Level.INFO, o.toString(), t);
+    }
+
+    @Override
+    public void warn(Object o) {
+        logger.warning(o.toString());
+    }
+
+    @Override
+    public void warn(Object o, Throwable t) {
+        logger.log(Level.WARNING, o.toString(), t);
+    }
+
+    @Override
+    public void error(Object o) {
+        logger.severe(o.toString());
+    }
+
+    @Override
+    public void error(Object o, Throwable t) {
+        logger.log(Level.SEVERE, o.toString(), t);
+    }
+
+    @Override
+    public void fatal(Object o) {
+        logger.severe(o.toString());
+    }
+
+    @Override
+    public void fatal(Object o, Throwable t) {
+        logger.log(Level.SEVERE, o.toString(), t);
+    }
+}

Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALogFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALogFactory.java?rev=1239288&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALogFactory.java
(added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/openjpa/JULOpenJPALogFactory.java
Wed Feb  1 19:51:28 2012
@@ -0,0 +1,11 @@
+package org.apache.openejb.openjpa;
+
+import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.log.LogFactoryAdapter;
+
+public class JULOpenJPALogFactory extends LogFactoryAdapter {
+    @Override
+    protected Log newLogAdapter(final String channel) {
+        return new JULOpenJPALog(channel);
+    }
+}

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java?rev=1239288&r1=1239287&r2=1239288&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/JuliLogStreamFactory.java
Wed Feb  1 19:51:28 2012
@@ -35,6 +35,12 @@ public class JuliLogStreamFactory implem
 
         // if embedded case enhance a bit logging if not set
         if ((!tomee || embedded) && System.getProperty("java.util.logging.manager")
== null) {
+            try {
+                JuliLogStreamFactory.class.getClassLoader().loadClass("org.apache.openjpa.lib.log.LogFactoryAdapter");
+                System.setProperty("openjpa.Log", "org.apache.openejb.openjpa.JULOpenJPALogFactory");
+            } catch (Exception ignored) {
+                // no-op: openjpa is not at the classpath so don't trigger it loading with
our logger
+            }
             System.setProperty("java.util.logging.manager", OpenEJBLogManager.class.getName());
         }
     }
@@ -44,7 +50,7 @@ public class JuliLogStreamFactory implem
         public String getProperty(final String name) {
             final String parentValue = super.getProperty(name);
             // if it is one of ours loggers and no value is defined let set our nice logging
style
-            if (OpenEJBLogManager.class.getName().equals(System.getProperty("java.util.logging.manager"))
// custom loggin
+            if (OpenEJBLogManager.class.getName().equals(System.getProperty("java.util.logging.manager"))
// custom logging
                     && isOverridableLogger(name) // managed loggers
                     && parentValue == null) { // not already defined
                 if (name.endsWith(".handlers")) {



Mime
View raw message