[jboss-svn-commits] JBoss Common SVN: r3020 - in jboss-logbridge/trunk: src/main/java/org/jboss/logbridge and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Mar 5 16:28:52 EST 2009
Author: david.lloyd at jboss.com
Date: 2009-03-05 16:28:52 -0500 (Thu, 05 Mar 2009)
New Revision: 3020
Added:
jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeHierarchy.java
jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeLogger.java
jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeRootLogger.java
Modified:
jboss-logbridge/trunk/pom.xml
jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LevelMapper.java
jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LogBridgeHandler.java
Log:
Add log4j hooks to detect and propagate log level changes (part 2 of fixing symptom caused by the JSF bug in JBCTS-634)
Modified: jboss-logbridge/trunk/pom.xml
===================================================================
--- jboss-logbridge/trunk/pom.xml 2009-03-05 18:15:47 UTC (rev 3019)
+++ jboss-logbridge/trunk/pom.xml 2009-03-05 21:28:52 UTC (rev 3020)
@@ -7,7 +7,7 @@
<groupId>org.jboss.logbridge</groupId>
<artifactId>jboss-logbridge</artifactId>
<packaging>jar</packaging>
- <version>1.0.0.CR1</version>
+ <version>1.0.0.CR2</version>
<dependencies>
<dependency>
<groupId>apache-log4j</groupId>
Added: jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeHierarchy.java
===================================================================
--- jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeHierarchy.java (rev 0)
+++ jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeHierarchy.java 2009-03-05 21:28:52 UTC (rev 3020)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * 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.
+ *
+ * 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.logbridge;
+
+import org.apache.log4j.Hierarchy;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LoggerFactory;
+
+public final class BridgeHierarchy extends Hierarchy {
+
+ private final LogBridgeHandler logBridgeHandler;
+ private final Factory factory = new Factory();
+
+ public BridgeHierarchy(Logger logger, final LogBridgeHandler handler) {
+ super(logger);
+ logBridgeHandler = handler;
+ }
+
+ public Logger getRootLogger() {
+ return super.getRootLogger();
+ }
+
+ public Logger getLogger(final String s, final LoggerFactory factory) {
+ return super.getLogger(s, factory);
+ }
+
+ public Logger getLogger(final String s) {
+ return super.getLogger(s, factory);
+ }
+
+ LogBridgeHandler getLogBridgeHandler() {
+ return logBridgeHandler;
+ }
+
+ private class Factory implements LoggerFactory {
+
+ public Logger makeNewLoggerInstance(final String s) {
+ return new BridgeLogger(s);
+ }
+ }
+}
Added: jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeLogger.java
===================================================================
--- jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeLogger.java (rev 0)
+++ jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeLogger.java 2009-03-05 21:28:52 UTC (rev 3020)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * 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.
+ *
+ * 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.logbridge;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+import org.apache.log4j.Priority;
+
+public class BridgeLogger extends Logger {
+
+ protected BridgeLogger(String s) {
+ super(s);
+ }
+
+ @SuppressWarnings({ "NonConstantLogger" })
+ private java.util.logging.Logger jdkLogger;
+
+ public void setLevel(final Level level) {
+ super.setLevel(level);
+ syncLevels();
+ }
+
+ @SuppressWarnings({ "deprecation" })
+ @Deprecated
+ public void setPriority(final Priority priority) {
+ super.setPriority(priority);
+ syncLevels();
+ }
+
+ private void syncLevels() {
+ synchronized (this) {
+ if (jdkLogger == null) {
+ jdkLogger = java.util.logging.Logger.getLogger(name);
+ }
+ final BridgeHierarchy bridgeHierarchy = (BridgeHierarchy) repository;
+ if (bridgeHierarchy == null) {
+ // not fully initialized yet; bail out
+ return;
+ }
+ final LevelMapper mapper = bridgeHierarchy.getLogBridgeHandler().getLevelMapper();
+ final Level ourLevel = getLevel();
+ if (ourLevel == null) {
+ jdkLogger.setLevel(null);
+ } else {
+ jdkLogger.setLevel(mapper.getSourceLevelForTargetLevel(ourLevel));
+ }
+ }
+ }
+}
Added: jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeRootLogger.java
===================================================================
--- jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeRootLogger.java (rev 0)
+++ jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/BridgeRootLogger.java 2009-03-05 21:28:52 UTC (rev 3020)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * 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.
+ *
+ * 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.logbridge;
+
+import org.apache.log4j.Level;
+
+public final class BridgeRootLogger extends BridgeLogger {
+
+ protected BridgeRootLogger(Level level) {
+ super("root");
+ if (level == null) {
+ throw new NullPointerException("level is null");
+ }
+ setLevel(level);
+ }
+
+ public void setLevel(final Level level) {
+ if (level != null) super.setLevel(level);
+ }
+}
Modified: jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LevelMapper.java
===================================================================
--- jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LevelMapper.java 2009-03-05 18:15:47 UTC (rev 3019)
+++ jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LevelMapper.java 2009-03-05 21:28:52 UTC (rev 3020)
@@ -51,7 +51,8 @@
registerMapping(Level.FATAL, new SourceLevelKey(org.jboss.logmanager.Level.FATAL));
registerMapping(Level.ERROR, new SourceLevelKey(org.jboss.logmanager.Level.ERROR));
registerMapping(Level.WARN, new SourceLevelKey(org.jboss.logmanager.Level.WARN));
- registerMapping(Level.INFO, new SourceLevelKey(org.jboss.logmanager.Level.INFO));
+ // Don't log the log4j info level; any logging from JDK INFO should go to JDKLevel.INFO.
+ // registerMapping(Level.INFO, new SourceLevelKey(org.jboss.logmanager.Level.INFO));
registerMapping(Level.DEBUG, new SourceLevelKey(org.jboss.logmanager.Level.DEBUG));
registerMapping(Level.TRACE, new SourceLevelKey(org.jboss.logmanager.Level.TRACE));
}
Modified: jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LogBridgeHandler.java
===================================================================
--- jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LogBridgeHandler.java 2009-03-05 18:15:47 UTC (rev 3019)
+++ jboss-logbridge/trunk/src/main/java/org/jboss/logbridge/LogBridgeHandler.java 2009-03-05 21:28:52 UTC (rev 3020)
@@ -22,12 +22,19 @@
package org.jboss.logbridge;
+import java.util.Collections;
+import java.util.Enumeration;
+
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Filter;
import java.util.logging.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Appender;
+import org.apache.log4j.spi.LoggerRepository;
+import org.apache.log4j.spi.RepositorySelector;
/**
*
@@ -63,9 +70,43 @@
public void start() {
rootLogger.addHandler(this);
+ final LoggerRepository newRepos = new BridgeHierarchy(new BridgeRootLogger(org.apache.log4j.Level.DEBUG), this);
+ final LoggerRepository oldRepos = LogManager.getLoggerRepository();
+ // Copy over all the logger data, with appenders.
+ final Enumeration le = oldRepos.getCurrentLoggers();
+ while (le.hasMoreElements()) {
+ final Logger oldLogger = (Logger) le.nextElement();
+ final String name = oldLogger.getName();
+ final Logger newLogger = newRepos.getLogger(name);
+ copyAppenders(oldLogger, newLogger);
+ final org.apache.log4j.Level oldLevel = oldLogger.getLevel();
+ if (oldLevel != null) {
+ newLogger.setLevel(oldLevel);
+ }
+ newLogger.setAdditivity(oldLogger.getAdditivity());
+ newLogger.setResourceBundle(oldLogger.getResourceBundle());
+ }
+ copyAppenders(oldRepos.getRootLogger(), newRepos.getRootLogger());
+ LogManager.setRepositorySelector(new RepositorySelector() {
+ public LoggerRepository getLoggerRepository() {
+ return newRepos;
+ }
+ }, null);
}
+ private static void copyAppenders(final Logger oldLogger, final Logger newLogger) {
+ final Enumeration ae = oldLogger.getAllAppenders();
+ while (ae.hasMoreElements()) {
+ final Appender appender = (Appender) ae.nextElement();
+ newLogger.addAppender(appender);
+ }
+ }
+
public void stop() {
rootLogger.removeHandler(this);
}
+
+ LevelMapper getLevelMapper() {
+ return levelMapper;
+ }
}
More information about the jboss-svn-commits
mailing list