[jboss-cvs] JBossAS SVN: r86864 - projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 6 14:02:27 EDT 2009
Author: stan.silvert at jboss.com
Date: 2009-04-06 14:02:27 -0400 (Mon, 06 Apr 2009)
New Revision: 86864
Removed:
projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/FaceletsLoggers.java
projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/Log4JConversionFilter.java
Modified:
projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/JBossJSFConfigureListener.java
Log:
JBAS-6580 Remove logging bridge
Deleted: projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/FaceletsLoggers.java
===================================================================
--- projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/FaceletsLoggers.java 2009-04-06 17:58:26 UTC (rev 86863)
+++ projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/FaceletsLoggers.java 2009-04-06 18:02:27 UTC (rev 86864)
@@ -1,166 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jsf.integration.config;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.logging.Logger;
-
-/**
- * This class provides access to the loggers used by Facelets version 1.1.15.
- *
- * @author Stan Silvert
- * @author Pete Muir
- */
-public class FaceletsLoggers
-{
-
- // Don't allow an instance of this class
- private FaceletsLoggers() {}
-
- /**
- * Determine if Facelets is in the classpath.
- *
- * @return <code>true</code> if Facelets is available,
- * <code>false</code> otherwise.
- */
- public static boolean isFaceletsAvailable()
- {
- try
- {
- classForName("com.sun.facelets.Facelet");
- return true;
- }
- catch (ClassNotFoundException e)
- {
- return false;
- }
- }
-
- /**
- * Return an Iterator of all the java.util.logging.Logger objects used
- * in Facelets.
- *
- * @return The Loggers, or an empty Iterator if Facelets is not available.
- */
- public static Iterator<Logger> getLoggers() throws Exception
- {
- List<Logger> loggers = new ArrayList<Logger>();
-
- if (!isFaceletsAvailable()) return loggers.iterator();
-
- // Gah have to do this by reflection as the loggers are protected
-
- // And some aren't static, so this really is best effort
- loggers.add(getPrivateStaticLogger("com.sun.facelets.compiler.TagLibraryConfig", "log"));
- loggers.add(getPrivateStaticLogger("com.sun.facelets.compiler.Compiler", "log"));
- loggers.add(getPrivateStaticLogger("com.sun.facelets.impl.DefaultFaceletFactory", "log"));
- loggers.add(getPrivateStaticLogger("com.sun.facelets.tag.jsf.ComponentHandler", "log"));
- loggers.add(getPrivateStaticLogger("com.sun.facelets.util.Resource", "log"));
- loggers.add(getPrivateStaticLogger("com.sun.facelets.FaceletViewHandler", "log"));
-
- // These ones are in a package-scoped class
- loggers.add(getPrivateStaticLogger("com.sun.facelets.compiler.CompilationManager", "log"));
- loggers.add(getPrivateStaticLogger("com.sun.facelets.tag.jsf.ComponentRule", "log"));
- loggers.add(getPrivateStaticLogger("com.sun.facelets.tag.MetaRulesetImpl", "log"));
-
- return loggers.iterator();
- }
-
- private static Logger getPrivateStaticLogger(Class clazz, String fieldName) throws Exception
- {
- Field field = getField(clazz, fieldName);
- field.setAccessible(true);
- return (Logger) get(field, new Object());
- }
-
- private static Logger getPrivateStaticLogger(String className, String fieldName) throws Exception
- {
- return getPrivateStaticLogger(classForName(className), fieldName);
- }
-
- // Code copied from org.jboss.seam.util.Reflctions
- private static Object get(Field field, Object target) throws Exception
- {
- try
- {
- return field.get(target);
- }
- catch (IllegalArgumentException iae)
- {
- String message = "Could not get field value by reflection: " + toString(field) +
- " on: " + target.getClass().getName();
- throw new IllegalArgumentException(message, iae);
- }
- }
-
- // Code copied from org.jboss.seam.util.Reflctions
- private static Field getField(Class clazz, String name)
- {
- for ( Class superClass = clazz; superClass!=Object.class; superClass=superClass.getSuperclass() )
- {
- try
- {
- return superClass.getDeclaredField(name);
- }
- catch (NoSuchFieldException nsfe) {}
- }
- throw new IllegalArgumentException("no such field: " + clazz.getName() + '.' + name);
- }
-
- // Code copied from org.jboss.seam.util.Reflctions
- private static Class classForName(String name) throws ClassNotFoundException
- {
- try
- {
- return Thread.currentThread().getContextClassLoader().loadClass(name);
- }
- catch (Exception e)
- {
- return Class.forName(name);
- }
- }
-
- // Code copied from org.jboss.seam.util.Reflctions
- private static String toString(Member member)
- {
- return unqualify( member.getDeclaringClass().getName() ) +
- '.' +
- member.getName();
- }
-
- // Code copied from org.jboss.seam.util.Strings
- private static String unqualify(String name)
- {
- return unqualify(name, '.');
- }
-
- // Code copied from org.jboss.seam.util.Strings
- private static String unqualify(String name, char sep)
- {
- return name.substring( name.lastIndexOf(sep)+1, name.length() );
- }
-
-}
Modified: projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/JBossJSFConfigureListener.java
===================================================================
--- projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/JBossJSFConfigureListener.java 2009-04-06 17:58:26 UTC (rev 86863)
+++ projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/JBossJSFConfigureListener.java 2009-04-06 18:02:27 UTC (rev 86864)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
@@ -22,12 +22,8 @@
package org.jboss.jsf.integration.config;
import com.sun.faces.config.ConfigureListener;
-import com.sun.faces.util.FacesLogger;
-import java.util.Iterator;
-import java.util.logging.Filter;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
-import org.apache.log4j.Level;
import org.jboss.logging.Logger;
/**
@@ -42,10 +38,6 @@
private static Logger LOG = Logger.getLogger(JBossJSFConfigureListener.class);
- public static final String BASE_JSF_LOGGER = "javax.enterprise.resource.webcontainer.jsf";
-
- public static final String SHOULD_LOG_CONFIG_MESSAGES = "com.sun.faces.displayConfiguration";
-
private ServletContext servletContext;
private boolean initialized = false;
@@ -62,20 +54,13 @@
this.servletContext = event.getServletContext();
if (warBundlesJSFImpl(this.servletContext)) return;
-// JBAS-6475, with the update to jboss-log-bridge this is not need
-// // If the pluginClass is not set, assume Log4J
-// if (System.getProperty("org.jboss.logging.Logger.pluginClass") == null)
-// {
-// setLog4J();
-// setLog4JForFacelets();
-// }
-
checkForMyFaces();
initializeJspRuntime();
initialized = true;
super.contextInitialized(event);
}
+ @Override
public void contextDestroyed(ServletContextEvent event)
{
if (initialized)
@@ -117,112 +102,4 @@
}
}
- /**
- * For a given JSF julLogger find the logging level set to the
- * corresponding log4jLogger. Then set the julLogger to the
- * same level as the log4jLogger.
- *
- * At this point we know that Log4J is being used. So we can
- * reference a real Log4J logger instead of the JBoss one.
- */
- private void setLevel(java.util.logging.Logger julLogger)
- {
- org.apache.log4j.Logger log4jLogger =
- org.apache.log4j.Logger.getLogger(julLogger.getName());
-
- julLogger.setLevel(java.util.logging.Level.OFF);
-
- if (log4jLogger.isEnabledFor(Level.FATAL))
- julLogger.setLevel(java.util.logging.Level.SEVERE);
-
- if (log4jLogger.isEnabledFor(Level.ERROR))
- julLogger.setLevel(java.util.logging.Level.SEVERE);
-
- if (log4jLogger.isEnabledFor(Level.WARN))
- julLogger.setLevel(java.util.logging.Level.WARNING);
-
- if (log4jLogger.isEnabledFor(Level.INFO))
- julLogger.setLevel(java.util.logging.Level.INFO);
-
- if (log4jLogger.isEnabledFor(Level.DEBUG))
- julLogger.setLevel(java.util.logging.Level.FINE);
-
- if (log4jLogger.isEnabledFor(Level.TRACE))
- julLogger.setLevel(java.util.logging.Level.FINEST);
-
- if (log4jLogger.isEnabledFor(Level.ALL))
- julLogger.setLevel(java.util.logging.Level.ALL);
- }
-
- private void setLog4JForFacelets()
- {
- Filter conversionFilter = new Log4JConversionFilter(logConfigMessages());
-
- try
- { // if Facelets is not used, getLoggers() returns an empty Iterator
- for (Iterator<java.util.logging.Logger> loggers = FaceletsLoggers.getLoggers(); loggers.hasNext();)
- {
- java.util.logging.Logger julLogger = loggers.next();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
- }
- }
- catch (Exception e)
- {
- LOG.warn("Unable to convert Facelets logging to Log4J", e);
- }
- }
-
- /**
- * If Log4J is being used, set a filter that converts JSF RI java.util.logger
- * messages to Log4J messages.
- */
- private void setLog4J()
- {
- Filter conversionFilter = new Log4JConversionFilter(logConfigMessages());
-
- java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(BASE_JSF_LOGGER);
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.APPLICATION.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.CONFIG.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.CONTEXT.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.LIFECYCLE.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.MANAGEDBEAN.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.RENDERKIT.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.TAGLIB.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
-
- julLogger = FacesLogger.TIMING.getLogger();
- setLevel(julLogger);
- julLogger.setFilter(conversionFilter);
- }
-
- // should we log the configuration messages?
- private boolean logConfigMessages()
- {
- String shouldLogConfigParam = this.servletContext.getInitParameter(SHOULD_LOG_CONFIG_MESSAGES);
- return (shouldLogConfigParam != null) && (shouldLogConfigParam.equalsIgnoreCase("true"));
- }
-
}
Deleted: projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/Log4JConversionFilter.java
===================================================================
--- projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/Log4JConversionFilter.java 2009-04-06 17:58:26 UTC (rev 86863)
+++ projects/jboss-jsf-int/trunk/jsf-deployer/src/main/java/org/jboss/jsf/integration/config/Log4JConversionFilter.java 2009-04-06 18:02:27 UTC (rev 86864)
@@ -1,183 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.jsf.integration.config;
-
-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 from the JSF RI
- * to Log4J messages.
- *
- * @author Stan Silvert
- */
-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();
-
- // should we log the INFO level config messages that tell about
- // servlet context params?
- private boolean logConfigMessages;
-
- public Log4JConversionFilter(boolean logConfigMessages)
- {
- this.logConfigMessages = logConfigMessages;
- }
-
- private boolean isConfigStartupMessage(LogRecord record)
- {
- return record.getMessage().equals("jsf.config.listener.version") ||
- record.getMessage().equals("jsf.config.listener.version.complete");
- }
-
- /**
- * 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)
- {
- if (!logConfigMessages && isConfigStartupMessage(record)) return false;
-
- 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 jboss-cvs-commits
mailing list