[seam-commits] Seam SVN: r7459 - in trunk: build and 10 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Feb 20 08:03:05 EST 2008


Author: pete.muir at jboss.org
Date: 2008-02-20 08:03:05 -0500 (Wed, 20 Feb 2008)
New Revision: 7459

Added:
   trunk/build/jul.pom.xml
   trunk/src/interop/
   trunk/src/interop/jul/
   trunk/src/interop/jul/org/
   trunk/src/interop/jul/org/jboss/
   trunk/src/interop/jul/org/jboss/seam/
   trunk/src/interop/jul/org/jboss/seam/interop/
   trunk/src/interop/jul/org/jboss/seam/interop/jul/
   trunk/src/interop/jul/org/jboss/seam/interop/jul/Log4JConversionFilter.java
Removed:
   trunk/src/jbas5/
   trunk/ui/src/main/java/org/jboss/seam/ui/facelet/Log4JConversionFilter.java
Modified:
   trunk/build.xml
   trunk/build/build.xml
   trunk/build/ci.build.xml
   trunk/build/classpath.tmpl
   trunk/build/common.build.xml
   trunk/build/root.pom.xml
   trunk/build/ui.pom.xml
   trunk/doc/reference/en/modules/configuration.xml
   trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletsJBossLogging.java
Log:
Need our own LoggerConversionFilter as the one in 4.2 needs JBAS-4432 fixed, and move jbas5 to src/interop

Modified: trunk/build/build.xml
===================================================================
--- trunk/build/build.xml	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/build/build.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -40,7 +40,8 @@
 		<deployWithSources pom="${pdf.pom}" jar="${lib.dir}/jboss-seam-pdf.jar" repositoryId="offline.repository.jboss.org" srcjar="${lib.dir}/src/jboss-seam-pdf-sources.jar"/>
 		<deployWithSources pom="${remoting.pom}" jar="${lib.dir}/jboss-seam-remoting.jar" repositoryId="offline.repository.jboss.org" srcjar="${lib.dir}/src/jboss-seam-remoting-sources.jar"/>
 		<deployWithSources pom="${ui.pom}" jar="${lib.dir}/jboss-seam-ui.jar" repositoryId="offline.repository.jboss.org" srcjar="${lib.dir}/src/jboss-seam-ui-sources.jar"/>
-		<deployWithSources pom="${jbas5.pom}" jar="${lib.dir}/jboss-seam-jbas5.jar" repositoryId="offline.repository.jboss.org" srcjar="${lib.dir}/src/jboss-seam-jbas5-sources.jar"/>
+		<deployWithSources pom="${jbas5.pom}" jar="${lib.dir}/interop/jboss-seam-jbas5.jar" repositoryId="offline.repository.jboss.org" srcjar="${lib.dir}/src/interop/jboss-seam-jbas5-sources.jar"/>
+		<deployWithSources pom="${jul.pom}" jar="${lib.dir}/interop/jboss-seam-jul.jar" repositoryId="offline.repository.jboss.org" srcjar="${lib.dir}/src/interop/jboss-seam-jul-sources.jar"/>
 		<deployExample name="booking" repositoryId="offline.repository.jboss.org"/>
 		<deployExampleNoDs name="numberguess" repositoryId="offline.repository.jboss.org"/>
 		<deployExample name="dvd" path="${seam.dir}/examples/dvdstore" repositoryId="offline.repository.jboss.org"/>

Modified: trunk/build/ci.build.xml
===================================================================
--- trunk/build/ci.build.xml	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/build/ci.build.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -21,6 +21,7 @@
 		<deploySnapshot pom="${core.pom}" jar="${lib.dir}/jboss-seam.jar" srcjar="${lib.dir}/src/jboss-seam-sources.jar" />
 		<deploySnapshot pom="${debug.pom}" jar="${lib.dir}/jboss-seam-debug.jar" srcjar="${lib.dir}/src/jboss-seam-debug-sources.jar"/>
         <deploySnapshot pom="${jbas5.pom}" jar="${lib.dir}/interop/jboss-seam-jbas5.jar" srcjar="${lib.dir}/interop/src/jboss-seam-jbas5-sources.jar"/>
+		<deploySnapshot pom="${jul.pom}" jar="${lib.dir}/interop/jboss-seam-jul.jar" srcjar="${lib.dir}/interop/src/jboss-seam-jul-sources.jar"/>
 		<deploySnapshot pom="${wicket.pom}" jar="${lib.dir}/jboss-seam-wicket.jar" srcjar="${lib.dir}/src/jboss-seam-wicket-sources.jar"/>
 		<deploySnapshot pom="${gen.pom}" jar="${lib.dir}/jboss-seam-gen.jar" srcjar="${lib.dir}/src/jboss-seam-gen-sources.jar"/>
 		<deploySnapshot pom="${ioc.pom}" jar="${lib.dir}/jboss-seam-ioc.jar" srcjar="${lib.dir}/src/jboss-seam-ioc-sources.jar"/>

Modified: trunk/build/classpath.tmpl
===================================================================
(Binary files differ)

Modified: trunk/build/common.build.xml
===================================================================
--- trunk/build/common.build.xml	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/build/common.build.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -96,6 +96,7 @@
 		<pomfile name="debug.pom" value="${build.dir}/debug.pom.xml" />
 		<pomfile name="wicket.pom" value="${build.dir}/wicket.pom.xml" />
         <pomfile name="jbas5.pom" value="${build.dir}/jbas5.pom.xml" />
+		<pomfile name="jul.pom" value="${build.dir}/jul.pom.xml" />
 		<pomfile name="gen.pom" value="${build.dir}/gen.pom.xml" />
 		<pomfile name="ioc.pom" value="${build.dir}/ioc.pom.xml" />
 		<pomfile name="mail.pom" value="${build.dir}/mail.pom.xml" />
@@ -333,6 +334,7 @@
 		<outputDependencyReport module="ioc" />
 		<outputDependencyReport module="wicket" />
 		<outputDependencyReport module="jbas5" />
+		<outputDependencyReport module="jul" />
 		<echo>Dependency Report written to ${seam.dir}/dependency-report.txt</echo>
 	</target>
 	

Added: trunk/build/jul.pom.xml
===================================================================
--- trunk/build/jul.pom.xml	                        (rev 0)
+++ trunk/build/jul.pom.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jboss.seam</groupId>
+	<artifactId>jboss-seam-jul</artifactId>
+	<parent>
+		<groupId>org.jboss.seam</groupId>
+		<artifactId>parent</artifactId>
+		<version>@seam.version@</version>
+	</parent>
+    <description>JUL -> Log4J conversion filter, used by Seam UI to instrument Facelets Logger</description>
+
+    <!-- See parent pom for notes on how to declare dependencies -->
+
+	<dependencies>
+   
+      <dependency>
+         <groupId>log4j</groupId>
+         <artifactId>log4j</artifactId>
+      </dependency>
+
+	</dependencies>
+
+</project>
\ No newline at end of file


Property changes on: trunk/build/jul.pom.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/build/root.pom.xml
===================================================================
--- trunk/build/root.pom.xml	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/build/root.pom.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -109,6 +109,12 @@
         <artifactId>jboss-seam-debug</artifactId>
         <version>@seam.version@</version>
       </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.seam</groupId>
+        <artifactId>jboss-seam-jul</artifactId>
+        <version>@seam.version@</version>
+      </dependency>
 
       <dependency>
         <groupId>javax.servlet</groupId>

Modified: trunk/build/ui.pom.xml
===================================================================
--- trunk/build/ui.pom.xml	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/build/ui.pom.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -79,6 +79,11 @@
       <groupId>org.jboss.seam</groupId>
       <artifactId>jboss-seam</artifactId>
     </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.seam</groupId>
+      <artifactId>jboss-seam-jul</artifactId>
+    </dependency>
 
     <dependency>
       <groupId>antlr</groupId>

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/build.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -20,6 +20,7 @@
 	<property name="classes.debug.dir" value="${classes.dir}/debugclasses" />
 	<property name="classes.wicket.dir" value="${classes.dir}/wicketclasses" />
 	<property name="classes.jbas5.dir" value="${classes.dir}/jbas5classes" />
+	<property name="classes.jul.dir" value="${classes.dir}/julclasses" />
 	<property name="classes.remoting.dir" value="${classes.dir}/remotingclasses" />
 	<property name="classes.gen.dir" value="${classes.dir}/genclasses" />
 	<property name="classes.test.dir" value="${classes.dir}/testclasses" />
@@ -35,7 +36,8 @@
 	<property name="src.mail.dir" value="src/mail" />
 	<property name="src.debug.dir" value="src/debug" />
 	<property name="src.wicket.dir" value="src/wicket" />
-	<property name="src.jbas5.dir" value="src/jbas5" />
+	<property name="src.jbas5.dir" value="src/interop/jbas5" />
+	<property name="src.jul.dir" value="src/interop/jul" />
 	<property name="src.gen.dir" value="src/gen" />
 	<property name="src.remoting.dir" value="src/remoting" />
 	<property name="src.test.dir" value="src/test" />
@@ -67,7 +69,8 @@
 	<property name="dist.src.mail.dir" value="${dist.dir}/src/mail" />
 	<property name="dist.src.debug.dir" value="${dist.dir}/src/debug" />
 	<property name="dist.src.wicket.dir" value="${dist.dir}/src/wicket" />
-	<property name="dist.src.jbas5.dir" value="${dist.dir}/src/jbas5" />
+	<property name="dist.src.jbas5.dir" value="${dist.dir}/src/interop/jbas5" />
+	<property name="dist.src.jbas5.dir" value="${dist.dir}/src/interop/jul" />
 	<property name="dist.src.gen.dir" value="${dist.dir}/src/gen" />
 	<property name="dist.src.remoting.dir" value="${dist.dir}/src/remoting" />
 	<property name="dist.src.test.dir" value="${dist.dir}/src/test" />
@@ -156,7 +159,7 @@
 		<delete dir="${lib.dir}" quiet="${quietclean}" />
 	</target>
 
-	<target name="build" depends="jarcore,jarpdf,jarioc,jarmail,jarremoting,jardebug,jargen,jarui,jarjbas5,jarwicket" description="Build all distribution .jar files" />
+	<target name="build" depends="jarcore,jarpdf,jarioc,jarmail,jarremoting,jardebug,jargen,jarui,jarjbas5,jarwicket, jarjul" description="Build all distribution .jar files" />
 
 	<target name="select-compiler">
 		<available classname="org.eclipse.jdt.core.JDTCompilerAdapter" property="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
@@ -278,7 +281,21 @@
 	<target name="jarjbas5" depends="compilejbas5" description="Build the distribution .jar file for the JBAS5 integration package">
 		<archive classesdir="${classes.jbas5.dir}" module="jboss-seam-jbas5" pom="${jbas5.pom}"  srcdir="${src.jbas5.dir}" outputdir="${lib.dir}/interop" />
 	</target>
+	
+	<!-- ########################### JUL TARGETS ###########################-->
 
+	<target name="initjul" depends="init, jarcore">
+		<init classesdir="${classes.jul.dir}" srcdir="${src.jul.dir}" modulename="jul" pom="${jul.pom}" />
+	</target>
+
+	<target name="compilejul" depends="initjul, select-compiler">
+		<compile classesdir="${classes.jul.dir}" srcdir="${src.jul.dir}" classpath="compile.jul.path" />
+	</target>
+
+	<target name="jarjul" depends="compilejul" description="Build the distribution .jar file for the JUL -> Log4J bridge integration package">
+		<archive classesdir="${classes.jul.dir}" module="jboss-seam-jul" pom="${jul.pom}"  srcdir="${src.jul.dir}" outputdir="${lib.dir}/interop" />
+	</target>
+
 	<!-- ########################### GEN TARGETS ###########################-->
 
 	<target name="initgen" depends="init">
@@ -310,7 +327,7 @@
 
 	<!-- ########################### UI TARGETS ###########################-->
 
-	<target name="initui" depends="init, jarcore">
+	<target name="initui" depends="init, jarcore, jarjul">
 		<dependencies id="ui" scope="compile" pom="${ui.pom}" />
 	</target>
 
@@ -451,6 +468,7 @@
 		<copysource destdir="${dist.src.debug.dir}" srcdir="${src.debug.dir}" />
 		<copysource destdir="${dist.src.wicket.dir}" srcdir="${src.wicket.dir}" />
 		<copysource destdir="${dist.src.jbas5.dir}" srcdir="${src.jbas5.dir}" />
+		<copysource destdir="${dist.src.jul.dir}" srcdir="${src.jul.dir}" />
 		<copysource destdir="${dist.src.gen.dir}" srcdir="${src.gen.dir}" />
 		<copysource destdir="${dist.src.test.dir}" srcdir="${src.test.dir}" />
 
@@ -927,6 +945,7 @@
 		<dependenciesWithSources id="debug" scope="compile" pom="${debug.pom}" />
 		<dependenciesWithSources id="wicket" scope="compile" pom="${wicket.pom}" />
 		<dependenciesWithSources id="jbas5" scope="compile" pom="${jbas5.pom}" />
+		<dependenciesWithSources id="jul" scope="compile" pom="${jul.pom}" />
 		<dependenciesWithSources id="gen" scope="compile" pom="${gen.pom}" />
 		<dependenciesWithSources id="ioc" scope="compile" pom="${ioc.pom}" />
 		<dependenciesWithSources id="mail" scope="compile" pom="${mail.pom}" />
@@ -956,6 +975,7 @@
 		<dependencies id="debug" scope="compile" pom="${debug.pom}" />
 		<dependencies id="wicket" scope="compile" pom="${wicket.pom}" />
 		<dependencies id="jbas5" scope="compile" pom="${jbas5.pom}" />
+		<dependencies id="jul" scope="compile" pom="${jul.pom}" />
 		<dependencies id="gen" scope="compile" pom="${gen.pom}" />
 		<dependencies id="ioc" scope="compile" pom="${ioc.pom}" />
 		<dependencies id="mail" scope="compile" pom="${mail.pom}" />
@@ -972,6 +992,7 @@
 			<path refid="compile.remoting.path" />
 			<path refid="compile.ui.path" />
 			<path refid="compile.jbas5.path" />
+			<path refid="compile.jul.path" />
 			<path refid="compile.wicket.path" />
 		</eclipseClasspath>
 	</target>

Modified: trunk/doc/reference/en/modules/configuration.xml
===================================================================
--- trunk/doc/reference/en/modules/configuration.xml	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/doc/reference/en/modules/configuration.xml	2008-02-20 13:03:05 UTC (rev 7459)
@@ -65,6 +65,15 @@
     <param-value>.xhtml</param-value>
 </context-param>]]></programlisting>
 
+            <para>
+               If you are using facelets in JBoss AS, you'll find that facelets
+               logging is broken. Seam provides a bridge to fix this, to use it
+               copy <literal>lib/interop/jboss-seam-jul.jar</literal> to
+               <literal>$JBOSS_HOME/server/default/deploy/jboss-web.deployer/jsf-libs/</literal>
+               and include the <literal>jboss-seam-ui.jar</literal> in the 
+               <literal>WEB-INF/lib</literal> of your application.
+            </para>
+
         </sect2>
 
         <sect2>

Added: trunk/src/interop/jul/org/jboss/seam/interop/jul/Log4JConversionFilter.java
===================================================================
--- trunk/src/interop/jul/org/jboss/seam/interop/jul/Log4JConversionFilter.java	                        (rev 0)
+++ trunk/src/interop/jul/org/jboss/seam/interop/jul/Log4JConversionFilter.java	2008-02-20 13:03:05 UTC (rev 7459)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.seam.interop.jul;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Filter;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+
+import org.apache.log4j.Logger;
+
+/**
+ * This filter is used to convert java.util.logging messages from the JUL
+ * to Log4J messages.
+ * 
+ * You need to install it onto any JUL Logger which needs bridging 
+ * using logger.setFilter();
+ *
+ * @author Stan Silvert
+ * @author Pete Muir
+ */
+public class Log4JConversionFilter implements Filter 
+{
+    
+    // cache Logger instances.  Logger.getLogger() is known to be slow.
+    // See http://www.qos.ch/logging/thinkAgain.jsp
+    private Map<String, Logger> loggerCache = new HashMap<String, Logger>();
+    
+    private Formatter formatter = new SimpleFormatter();
+    
+    /**
+     * If the JSF RI message should be logged, convert the JDK 1.4 
+     * LogRecord to a Log4J message.
+     *
+     * @return <code>false</code> because JDK 1.4 logging should not happen
+     *         for JSF if this filter is active.
+     */
+    public boolean isLoggable(LogRecord record) 
+    {
+        
+        Logger logger = getLogger(record);
+        
+        if (record.getThrown() != null) 
+        {
+            logWithThrowable(logger, record);
+        } 
+        else 
+        {
+            logWithoutThrowable(logger, record);
+        }
+        
+        return false;
+    }
+    
+    private void logWithThrowable(Logger logger, LogRecord record) 
+    {
+        int loggedLevel = record.getLevel().intValue();
+        Object message = formatter.formatMessage(record);
+        Throwable throwable = record.getThrown();
+        
+        if (loggedLevel == Level.SEVERE.intValue())
+        {
+           logger.error(message, throwable);
+           return;
+        }
+
+        if (loggedLevel == Level.WARNING.intValue())
+        {
+           logger.warn(message, throwable);
+           return;
+        }
+
+        if ((loggedLevel == Level.INFO.intValue()) ||
+            (loggedLevel == Level.CONFIG.intValue()))
+        {
+           logger.info(message, throwable);
+           return;
+        }
+        
+        if (loggedLevel == Level.FINE.intValue())
+        {
+           logger.debug(message, throwable);
+           return;
+        }
+
+        if ((loggedLevel == Level.FINER.intValue()) ||
+            (loggedLevel == Level.FINEST.intValue()))
+        {
+           logger.trace(message, throwable);
+           return;
+        }
+    
+        logger.info(message, throwable);
+    }
+    
+    private void logWithoutThrowable(Logger logger, LogRecord record) 
+    {
+        int loggedLevel = record.getLevel().intValue();
+        Object message = formatter.formatMessage(record);
+        
+        if (loggedLevel == Level.SEVERE.intValue())
+        {
+           logger.error(message);
+           return;
+        }
+
+        if (loggedLevel == Level.WARNING.intValue())
+        {
+           logger.warn(message);
+           return;
+        }
+
+        if ((loggedLevel == Level.INFO.intValue()) ||
+            (loggedLevel == Level.CONFIG.intValue()))
+        {
+           logger.info(message);
+           return;
+        }
+        
+        if (loggedLevel == Level.FINE.intValue())
+        {
+           logger.debug(message);
+           return;
+        }
+
+        if ((loggedLevel == Level.FINER.intValue()) ||
+            (loggedLevel == Level.FINEST.intValue()))
+        {
+           logger.trace(message);
+           return;
+        }
+
+        logger.info(message);
+    }
+    
+    // get the Log4J logger corresponding to the java.util.logger.LogRecord
+    private Logger getLogger(LogRecord record) 
+    {
+        String loggerName = record.getLoggerName();
+        Logger logger = loggerCache.get(loggerName);
+        if (logger == null) 
+        {
+            logger = Logger.getLogger(loggerName);
+            loggerCache.put(loggerName, logger);
+        }
+        
+        return logger;
+    }
+    
+}


Property changes on: trunk/src/interop/jul/org/jboss/seam/interop/jul/Log4JConversionFilter.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletsJBossLogging.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletsJBossLogging.java	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletsJBossLogging.java	2008-02-20 13:03:05 UTC (rev 7459)
@@ -14,6 +14,7 @@
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.Startup;
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.interop.jul.Log4JConversionFilter;
 import org.jboss.seam.log.LogProvider;
 import org.jboss.seam.log.Logging;
 import org.jboss.seam.util.Reflections;
@@ -67,9 +68,19 @@
    @Create
    public void create()
    {
+      Filter conversionFilter;
       try
       {
-         Filter conversionFilter = new org.jboss.seam.ui.facelet.Log4JConversionFilter();
+         conversionFilter = new Log4JConversionFilter();
+      }
+      catch (Exception e) 
+      {
+         // Filter isn't installed in the container
+         return;
+      }
+      try
+      {
+         
    
          java.util.logging.Logger julLogger;
    

Deleted: trunk/ui/src/main/java/org/jboss/seam/ui/facelet/Log4JConversionFilter.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/facelet/Log4JConversionFilter.java	2008-02-20 13:00:55 UTC (rev 7458)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/facelet/Log4JConversionFilter.java	2008-02-20 13:03:05 UTC (rev 7459)
@@ -1,167 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.seam.ui.facelet;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Filter;
-import java.util.logging.Formatter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.SimpleFormatter;
-import org.jboss.logging.Logger;
-
-/**
- * This filter is used to convert java.util.logging messages to Log4J messages.
- *
- * @author Stan Silvert
- * @author Pete Muir
- */
-public class Log4JConversionFilter implements Filter 
-{
-    
-    // cache Logger instances.  Logger.getLogger() is known to be slow.
-    // See http://www.qos.ch/logging/thinkAgain.jsp
-    private Map<String, Logger> loggerCache = new HashMap<String, Logger>();
-    
-    private Formatter formatter = new SimpleFormatter();
-    
-    /**
-     * If the message should be logged, convert the JDK 1.4 
-     * LogRecord to a Log4J message.
-     *
-     * @return <code>false</code> because JDK 1.4 logging should not happen
-     *         for JSF if this filter is active.
-     */
-    public boolean isLoggable(LogRecord record) 
-    {   
-        Logger logger = getLogger(record);
-        
-        if (record.getThrown() != null) 
-        {
-            logWithThrowable(logger, record);
-        } 
-        else 
-        {
-            logWithoutThrowable(logger, record);
-        }
-        
-        return false;
-    }
-    
-    private void logWithThrowable(Logger logger, LogRecord record) 
-    {
-        int loggedLevel = record.getLevel().intValue();
-        Object message = formatter.formatMessage(record);
-        Throwable throwable = record.getThrown();
-        
-        if (loggedLevel == Level.SEVERE.intValue())
-        {
-           logger.error(message, throwable);
-           return;
-        }
-
-        if (loggedLevel == Level.WARNING.intValue())
-        {
-           logger.warn(message, throwable);
-           return;
-        }
-
-        if ((loggedLevel == Level.INFO.intValue()) ||
-            (loggedLevel == Level.CONFIG.intValue()))
-        {
-           logger.info(message, throwable);
-           return;
-        }
-        
-        if (loggedLevel == Level.FINE.intValue())
-        {
-           logger.debug(message, throwable);
-           return;
-        }
-
-        if ((loggedLevel == Level.FINER.intValue()) ||
-            (loggedLevel == Level.FINEST.intValue()))
-        {
-           logger.trace(message, throwable);
-           return;
-        }
-    
-        logger.info(message, throwable);
-    }
-    
-    private void logWithoutThrowable(Logger logger, LogRecord record) 
-    {
-        int loggedLevel = record.getLevel().intValue();
-        Object message = formatter.formatMessage(record);
-        
-        if (loggedLevel == Level.SEVERE.intValue())
-        {
-           logger.error(message);
-           return;
-        }
-
-        if (loggedLevel == Level.WARNING.intValue())
-        {
-           logger.warn(message);
-           return;
-        }
-
-        if ((loggedLevel == Level.INFO.intValue()) ||
-            (loggedLevel == Level.CONFIG.intValue()))
-        {
-           logger.info(message);
-           return;
-        }
-        
-        if (loggedLevel == Level.FINE.intValue())
-        {
-           logger.debug(message);
-           return;
-        }
-
-        if ((loggedLevel == Level.FINER.intValue()) ||
-            (loggedLevel == Level.FINEST.intValue()))
-        {
-           logger.trace(message);
-           return;
-        }
-
-        logger.info(message);
-    }
-    
-    // get the Log4J logger corresponding to the java.util.logger.LogRecord
-    private Logger getLogger(LogRecord record) 
-    {
-        String loggerName = record.getLoggerName();
-        Logger logger = loggerCache.get(loggerName);
-        if (logger == null) 
-        {
-            logger = Logger.getLogger(loggerName);
-            loggerCache.put(loggerName, logger);
-        }
-        
-        return logger;
-    }
-    
-}




More information about the seam-commits mailing list