[jboss-svn-commits] JBoss Common SVN: r3213 - in jboss-logmanager/trunk: src/main/java/org/jboss/logmanager and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 3 19:07:34 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-06-03 19:07:34 -0400 (Wed, 03 Jun 2009)
New Revision: 3213
Added:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java
jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLogger.java
Removed:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Slf4jLogger.java
Modified:
jboss-logmanager/trunk/pom.xml
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/log4j/Log4jAppenderHandler.java
jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLoggerFactory.java
Log:
Improved SPI, package cleanups, dep fixes, ExtHandler base
Modified: jboss-logmanager/trunk/pom.xml
===================================================================
--- jboss-logmanager/trunk/pom.xml 2009-06-03 00:45:45 UTC (rev 3212)
+++ jboss-logmanager/trunk/pom.xml 2009-06-03 23:07:34 UTC (rev 3213)
@@ -55,6 +55,16 @@
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<optional>true</optional>
+ <exclusions>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
<build>
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java 2009-06-03 00:45:45 UTC (rev 3212)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java 2009-06-03 23:07:34 UTC (rev 3213)
@@ -261,63 +261,6 @@
// Logger
- /**
- * Do the logging with no level checks (they've already been done).
- *
- * @param record the log record
- */
- void doLog(final LogRecord record) {
- doLog((record instanceof ExtLogRecord) ? (ExtLogRecord) record : new ExtLogRecord(record, LOGGER_CLASS_NAME));
- }
-
- /**
- * Do the logging with no level checks (they've already been done).
- *
- * @param record the log record
- */
- private void doLog(final ExtLogRecord record) {
- record.setLoggerName(getName());
- String bundleName = null;
- ResourceBundle bundle = null;
- for (Logger current = this; current != null; current = current.getParent()) {
- bundleName = current.getResourceBundleName();
- if (bundleName != null) {
- bundle = current.getResourceBundle();
- break;
- }
- }
- if (bundleName != null && bundle != null) {
- record.setResourceBundleName(bundleName);
- record.setResourceBundle(bundle);
- }
- final Filter filter = this.filter;
- try {
- if (filter != null && ! filter.isLoggable(record)) {
- return;
- }
- } catch (VirtualMachineError e) {
- throw e;
- } catch (Throwable t) {
- // todo - error handler
- // treat an errored filter as "pass" (I guess?)
- }
- for (Logger current = this; current != null; current = current.getParent()) {
- final Handler[] handlers = current.handlers;
- if (handlers != null) {
- for (Handler handler : handlers) try {
- handler.publish(record);
- } catch (VirtualMachineError e) {
- throw e;
- } catch (Throwable t) {
- // todo - error handler
- }
- }
- if (! current.useParentHandlers) {
- break;
- }
- }
- }
-
private static final int OFF_INT = Level.OFF.intValue();
private static final int SEVERE_INT = Level.SEVERE.intValue();
@@ -328,20 +271,13 @@
private static final int FINER_INT = Level.FINER.intValue();
private static final int FINEST_INT = Level.FINEST.intValue();
- static final int ALT_FATAL_INT = org.jboss.logmanager.Level.FATAL.intValue();
- static final int ALT_ERROR_INT = org.jboss.logmanager.Level.ERROR.intValue();
- static final int ALT_WARN_INT = org.jboss.logmanager.Level.WARN.intValue();
- static final int ALT_INFO_INT = org.jboss.logmanager.Level.INFO.intValue();
- static final int ALT_DEBUG_INT = org.jboss.logmanager.Level.DEBUG.intValue();
- static final int ALT_TRACE_INT = org.jboss.logmanager.Level.TRACE.intValue();
-
/** {@inheritDoc} */
public void log(LogRecord record) {
final int effectiveLevel = this.effectiveLevel;
if (record.getLevel().intValue() < effectiveLevel || effectiveLevel == OFF_INT) {
return;
}
- doLog(record);
+ logRaw(record);
}
/** {@inheritDoc} */
@@ -352,7 +288,7 @@
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "ENTRY", LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -364,7 +300,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setParameters(new Object[] { param1 });
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -380,7 +316,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
if (params != null) rec.setParameters(params);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -391,7 +327,7 @@
final ExtLogRecord rec = new ExtLogRecord(Level.FINER, "RETURN", LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -403,7 +339,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setParameters(new Object[] { result });
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -415,7 +351,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -423,7 +359,7 @@
if (SEVERE_INT < effectiveLevel) {
return;
}
- doLog(new ExtLogRecord(Level.SEVERE, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(Level.SEVERE, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -431,7 +367,7 @@
if (WARNING_INT < effectiveLevel) {
return;
}
- doLog(new ExtLogRecord(Level.WARNING, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(Level.WARNING, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -439,7 +375,7 @@
if (INFO_INT < effectiveLevel) {
return;
}
- doLog(new ExtLogRecord(Level.INFO, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(Level.INFO, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -447,7 +383,7 @@
if (CONFIG_INT < effectiveLevel) {
return;
}
- doLog(new ExtLogRecord(Level.CONFIG, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(Level.CONFIG, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -455,7 +391,7 @@
if (FINE_INT < effectiveLevel) {
return;
}
- doLog(new ExtLogRecord(Level.FINE, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(Level.FINE, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -463,7 +399,7 @@
if (FINER_INT < effectiveLevel) {
return;
}
- doLog(new ExtLogRecord(Level.FINER, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(Level.FINER, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -471,7 +407,7 @@
if (FINEST_INT < effectiveLevel) {
return;
}
- doLog(new ExtLogRecord(Level.FINEST, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(Level.FINEST, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -480,7 +416,7 @@
if (level.intValue() < effectiveLevel || effectiveLevel == OFF_INT) {
return;
}
- doLog(new ExtLogRecord(level, msg, LOGGER_CLASS_NAME));
+ logRaw(new ExtLogRecord(level, msg, LOGGER_CLASS_NAME));
}
/** {@inheritDoc} */
@@ -491,7 +427,7 @@
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setParameters(new Object[] { param1 });
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -502,7 +438,7 @@
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
if (params != null) rec.setParameters(params);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -513,7 +449,7 @@
}
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setThrown(thrown);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -525,7 +461,7 @@
final ExtLogRecord rec = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -538,7 +474,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setParameters(new Object[] { param1 });
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -551,7 +487,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
if (params != null) rec.setParameters(params);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -564,7 +500,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setThrown(thrown);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -577,7 +513,7 @@
rec.setSourceClassName(sourceClass);
rec.setSourceMethodName(sourceMethod);
rec.setResourceBundleName(bundleName);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -591,7 +527,7 @@
rec.setSourceMethodName(sourceMethod);
rec.setResourceBundleName(bundleName);
rec.setParameters(new Object[] { param1 });
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -605,7 +541,7 @@
rec.setSourceMethodName(sourceMethod);
rec.setResourceBundleName(bundleName);
if (params != null) rec.setParameters(params);
- doLog(rec);
+ logRaw(rec);
}
/** {@inheritDoc} */
@@ -619,7 +555,7 @@
rec.setSourceMethodName(sourceMethod);
rec.setResourceBundleName(bundleName);
rec.setThrown(thrown);
- doLog(rec);
+ logRaw(rec);
}
// GC
@@ -638,7 +574,7 @@
}
}
- // alternate SPI hook
+ // alternate SPI hooks
/**
* SPI interface method to log a message at a given level.
@@ -653,7 +589,65 @@
if (level.intValue() >= effectiveLevel && effectiveLevel != OFF_INT) {
final ExtLogRecord rec = new ExtLogRecord(level, message, fqcn);
rec.setThrown(t);
- doLog(rec);
+ logRaw(rec);
}
}
+
+ /**
+ * Do the logging with no level checks (they've already been done).
+ *
+ * @param record the extended log record
+ */
+ public void logRaw(final ExtLogRecord record) {
+ record.setLoggerName(getName());
+ String bundleName = null;
+ ResourceBundle bundle = null;
+ for (Logger current = this; current != null; current = current.getParent()) {
+ bundleName = current.getResourceBundleName();
+ if (bundleName != null) {
+ bundle = current.getResourceBundle();
+ break;
+ }
+ }
+ if (bundleName != null && bundle != null) {
+ record.setResourceBundleName(bundleName);
+ record.setResourceBundle(bundle);
+ }
+ final Filter filter = this.filter;
+ try {
+ if (filter != null && ! filter.isLoggable(record)) {
+ return;
+ }
+ } catch (VirtualMachineError e) {
+ throw e;
+ } catch (Throwable t) {
+ // todo - error handler
+ // treat an errored filter as "pass" (I guess?)
+ }
+ for (Logger current = this; current != null; current = current.getParent()) {
+ final Handler[] handlers = current.handlers;
+ if (handlers != null) {
+ for (Handler handler : handlers) try {
+ handler.publish(record);
+ } catch (VirtualMachineError e) {
+ throw e;
+ } catch (Throwable t) {
+ // todo - error handler
+ }
+ }
+ if (! current.useParentHandlers) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Do the logging with no level checks (they've already been done). Creates an extended log record if the
+ * provided record is not one.
+ *
+ * @param record the log record
+ */
+ public void logRaw(final LogRecord record) {
+ logRaw((record instanceof ExtLogRecord) ? (ExtLogRecord) record : new ExtLogRecord(record, LOGGER_CLASS_NAME));
+ }
}
Deleted: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Slf4jLogger.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Slf4jLogger.java 2009-06-03 00:45:45 UTC (rev 3212)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Slf4jLogger.java 2009-06-03 23:07:34 UTC (rev 3213)
@@ -1,336 +0,0 @@
-/*
- * 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.logmanager;
-
-import org.slf4j.Marker;
-import org.slf4j.helpers.MarkerIgnoringBase;
-import org.slf4j.spi.LocationAwareLogger;
-
-import static org.jboss.logmanager.Logger.ALT_TRACE_INT;
-import static org.jboss.logmanager.Logger.ALT_DEBUG_INT;
-import static org.jboss.logmanager.Logger.ALT_INFO_INT;
-import static org.jboss.logmanager.Logger.ALT_WARN_INT;
-import static org.jboss.logmanager.Logger.ALT_ERROR_INT;
-import java.io.Serializable;
-import java.io.ObjectStreamException;
-
-public final class Slf4jLogger extends MarkerIgnoringBase implements Serializable, LocationAwareLogger {
- private final Logger logger;
- private static final String LOGGER_CLASS_NAME = Slf4jLogger.class.getName();
- private static final long serialVersionUID = -8422185592693034532L;
-
- public Slf4jLogger(final Logger logger) {
- this.logger = logger;
- }
-
- public String getName() {
- return logger.getName();
- }
-
- /** {@inheritDoc} */
- public void log(final Marker marker, final String fqcn, final int levelVal, final String message, final Throwable t) {
- // ignore marker
- final java.util.logging.Level level;
- switch (levelVal) {
- case LocationAwareLogger.TRACE_INT: level = org.jboss.logmanager.Level.TRACE; break;
- case LocationAwareLogger.DEBUG_INT: level = org.jboss.logmanager.Level.DEBUG; break;
- case LocationAwareLogger.INFO_INT: level = org.jboss.logmanager.Level.INFO; break;
- case LocationAwareLogger.WARN_INT: level = org.jboss.logmanager.Level.WARN; break;
- case LocationAwareLogger.ERROR_INT: level = org.jboss.logmanager.Level.ERROR; break;
- default: level = org.jboss.logmanager.Level.DEBUG; break;
- }
- final ExtLogRecord rec = new ExtLogRecord(level, message, fqcn);
- rec.setThrown(t);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public boolean isTraceEnabled() {
- return logger.isLoggable(Level.TRACE);
- }
-
- /** {@inheritDoc} */
- public void trace(final String msg) {
- if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
- return;
- }
- logger.doLog(new ExtLogRecord(org.jboss.logmanager.Level.TRACE, msg, LOGGER_CLASS_NAME));
- }
-
- /** {@inheritDoc} */
- public void trace(final String format, final Object arg) {
- if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void trace(final String format, final Object arg1, final Object arg2) {
- if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg1, arg2 });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void trace(final String format, final Object[] argArray) {
- if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, format, LOGGER_CLASS_NAME);
- rec.setParameters(argArray);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void trace(final String msg, final Throwable t) {
- if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, msg, LOGGER_CLASS_NAME);
- rec.setThrown(t);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public boolean isDebugEnabled() {
- return logger.isLoggable(Level.DEBUG);
- }
-
- /** {@inheritDoc} */
- public void debug(final String msg) {
- if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
- return;
- }
- logger.doLog(new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, msg, LOGGER_CLASS_NAME));
- }
-
- /** {@inheritDoc} */
- public void debug(final String format, final Object arg) {
- if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void debug(final String format, final Object arg1, final Object arg2) {
- if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg1, arg2 });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void debug(final String format, final Object[] argArray) {
- if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, format, LOGGER_CLASS_NAME);
- rec.setParameters(argArray);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void debug(final String msg, final Throwable t) {
- if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, msg, LOGGER_CLASS_NAME);
- rec.setThrown(t);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public boolean isInfoEnabled() {
- return logger.isLoggable(Level.INFO);
- }
-
- /** {@inheritDoc} */
- public void info(final String msg) {
- if (ALT_INFO_INT < logger.getEffectiveLevel()) {
- return;
- }
- logger.doLog(new ExtLogRecord(org.jboss.logmanager.Level.INFO, msg, LOGGER_CLASS_NAME));
- }
-
- /** {@inheritDoc} */
- public void info(final String format, final Object arg) {
- if (ALT_INFO_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void info(final String format, final Object arg1, final Object arg2) {
- if (ALT_INFO_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg1, arg2 });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void info(final String format, final Object[] argArray) {
- if (ALT_INFO_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, format, LOGGER_CLASS_NAME);
- rec.setParameters(argArray);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void info(final String msg, final Throwable t) {
- if (ALT_INFO_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, msg, LOGGER_CLASS_NAME);
- rec.setThrown(t);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public boolean isWarnEnabled() {
- return logger.isLoggable(Level.WARN);
- }
-
- /** {@inheritDoc} */
- public void warn(final String msg) {
- if (ALT_WARN_INT < logger.getEffectiveLevel()) {
- return;
- }
- logger.doLog(new ExtLogRecord(org.jboss.logmanager.Level.WARN, msg, LOGGER_CLASS_NAME));
- }
-
- /** {@inheritDoc} */
- public void warn(final String format, final Object arg) {
- if (ALT_WARN_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void warn(final String format, final Object arg1, final Object arg2) {
- if (ALT_WARN_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg1, arg2 });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void warn(final String format, final Object[] argArray) {
- if (ALT_WARN_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, format, LOGGER_CLASS_NAME);
- rec.setParameters(argArray);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void warn(final String msg, final Throwable t) {
- if (ALT_WARN_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, msg, LOGGER_CLASS_NAME);
- rec.setThrown(t);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public boolean isErrorEnabled() {
- return logger.isLoggable(Level.ERROR);
- }
-
- /** {@inheritDoc} */
- public void error(final String msg) {
- if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
- return;
- }
- logger.doLog(new ExtLogRecord(org.jboss.logmanager.Level.ERROR, msg, LOGGER_CLASS_NAME));
- }
-
- /** {@inheritDoc} */
- public void error(final String format, final Object arg) {
- if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void error(final String format, final Object arg1, final Object arg2) {
- if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, format, LOGGER_CLASS_NAME);
- rec.setParameters(new Object[] { arg1, arg2 });
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void error(final String format, final Object[] argArray) {
- if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, format, LOGGER_CLASS_NAME);
- rec.setParameters(argArray);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- public void error(final String msg, final Throwable t) {
- if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
- return;
- }
- final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, msg, LOGGER_CLASS_NAME);
- rec.setThrown(t);
- logger.doLog(rec);
- }
-
- /** {@inheritDoc} */
- protected Slf4jLogger readResolve() throws ObjectStreamException {
- return this;
- }
-}
Added: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/ExtHandler.java 2009-06-03 23:07:34 UTC (rev 3213)
@@ -0,0 +1,54 @@
+/*
+ * 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.logmanager.handlers;
+
+import org.jboss.logmanager.ExtLogRecord;
+
+import java.util.logging.Handler;
+import java.util.logging.LogRecord;
+
+/**
+ * An extended logger handler. Use this class as a base class for log handlers which require {@code ExtLogRecord}
+ * instances.
+ */
+public abstract class ExtHandler extends Handler {
+
+ private static final String LOGGER_CLASS_NAME = org.jboss.logmanager.Logger.class.getName();
+
+ /** {@inheritDoc} */
+ public final void publish(final LogRecord record) {
+ publish((record instanceof ExtLogRecord) ? (ExtLogRecord) record : new ExtLogRecord(record, LOGGER_CLASS_NAME));
+ }
+
+ /**
+ * Publish an {@code ExtLogRecord}.
+ * <p/>
+ * The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.
+ * <p/>
+ * The {@code ExtHandler} is responsible for formatting the message, when and if necessary. The formatting should
+ * include localization.
+ *
+ * @param record the log record to publish
+ */
+ public abstract void publish(final ExtLogRecord record);
+}
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/log4j/Log4jAppenderHandler.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/log4j/Log4jAppenderHandler.java 2009-06-03 00:45:45 UTC (rev 3212)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/handlers/log4j/Log4jAppenderHandler.java 2009-06-03 23:07:34 UTC (rev 3213)
@@ -25,16 +25,15 @@
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.jboss.logmanager.ExtLogRecord;
import org.jboss.logmanager.LogManager;
+import org.jboss.logmanager.handlers.ExtHandler;
-import java.util.logging.Handler;
-import java.util.logging.LogRecord;
import org.apache.log4j.Appender;
import org.apache.log4j.spi.LoggingEvent;
/**
* A handler which delegates to a log4j appender.
*/
-public final class Log4jAppenderHandler extends Handler {
+public final class Log4jAppenderHandler extends ExtHandler {
private volatile Appender appender = null;
private static final AtomicReferenceFieldUpdater<Log4jAppenderHandler, Appender> appenderUpdater = AtomicReferenceFieldUpdater.newUpdater(Log4jAppenderHandler.class, Appender.class, "appender");
@@ -53,13 +52,12 @@
*
* @param record the log record to publish
*/
- public void publish(final LogRecord record) {
+ public void publish(final ExtLogRecord record) {
final Appender appender = this.appender;
if (appender == null) {
throw new IllegalStateException("Appender is closed");
}
- final ExtLogRecord extRec = (record instanceof ExtLogRecord) ? (ExtLogRecord)record : new ExtLogRecord(record, java.util.logging.Logger.class.getName());
- final LoggingEvent event = new ConvertedLoggingEvent(extRec);
+ final LoggingEvent event = new ConvertedLoggingEvent(record);
appender.doAppend(event);
}
Copied: jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLogger.java (from rev 3206, jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Slf4jLogger.java)
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLogger.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLogger.java 2009-06-03 23:07:34 UTC (rev 3213)
@@ -0,0 +1,340 @@
+/*
+ * 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.slf4j.impl;
+
+import org.slf4j.Marker;
+import org.slf4j.helpers.MarkerIgnoringBase;
+import org.slf4j.spi.LocationAwareLogger;
+import org.jboss.logmanager.Logger;
+import org.jboss.logmanager.ExtLogRecord;
+import org.jboss.logmanager.Level;
+
+import java.io.Serializable;
+import java.io.ObjectStreamException;
+
+public final class Slf4jLogger extends MarkerIgnoringBase implements Serializable, LocationAwareLogger {
+ private final Logger logger;
+ private static final String LOGGER_CLASS_NAME = Slf4jLogger.class.getName();
+ private static final long serialVersionUID = -8422185592693034532L;
+
+ private static final int ALT_ERROR_INT = org.jboss.logmanager.Level.ERROR.intValue();
+ private static final int ALT_WARN_INT = org.jboss.logmanager.Level.WARN.intValue();
+ private static final int ALT_INFO_INT = org.jboss.logmanager.Level.INFO.intValue();
+ private static final int ALT_DEBUG_INT = org.jboss.logmanager.Level.DEBUG.intValue();
+ private static final int ALT_TRACE_INT = org.jboss.logmanager.Level.TRACE.intValue();
+
+ public Slf4jLogger(final Logger logger) {
+ this.logger = logger;
+ }
+
+ public String getName() {
+ return logger.getName();
+ }
+
+ /** {@inheritDoc} */
+ public void log(final Marker marker, final String fqcn, final int levelVal, final String message, final Throwable t) {
+ // ignore marker
+ final java.util.logging.Level level;
+ switch (levelVal) {
+ case LocationAwareLogger.TRACE_INT: level = org.jboss.logmanager.Level.TRACE; break;
+ case LocationAwareLogger.DEBUG_INT: level = org.jboss.logmanager.Level.DEBUG; break;
+ case LocationAwareLogger.INFO_INT: level = org.jboss.logmanager.Level.INFO; break;
+ case LocationAwareLogger.WARN_INT: level = org.jboss.logmanager.Level.WARN; break;
+ case LocationAwareLogger.ERROR_INT: level = org.jboss.logmanager.Level.ERROR; break;
+ default: level = org.jboss.logmanager.Level.DEBUG; break;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(level, message, fqcn);
+ rec.setThrown(t);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isTraceEnabled() {
+ return logger.isLoggable(Level.TRACE);
+ }
+
+ /** {@inheritDoc} */
+ public void trace(final String msg) {
+ if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ logger.logRaw(new ExtLogRecord(org.jboss.logmanager.Level.TRACE, msg, LOGGER_CLASS_NAME));
+ }
+
+ /** {@inheritDoc} */
+ public void trace(final String format, final Object arg) {
+ if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void trace(final String format, final Object arg1, final Object arg2) {
+ if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg1, arg2 });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void trace(final String format, final Object[] argArray) {
+ if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, format, LOGGER_CLASS_NAME);
+ rec.setParameters(argArray);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void trace(final String msg, final Throwable t) {
+ if (ALT_TRACE_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.TRACE, msg, LOGGER_CLASS_NAME);
+ rec.setThrown(t);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isDebugEnabled() {
+ return logger.isLoggable(Level.DEBUG);
+ }
+
+ /** {@inheritDoc} */
+ public void debug(final String msg) {
+ if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ logger.logRaw(new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, msg, LOGGER_CLASS_NAME));
+ }
+
+ /** {@inheritDoc} */
+ public void debug(final String format, final Object arg) {
+ if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void debug(final String format, final Object arg1, final Object arg2) {
+ if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg1, arg2 });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void debug(final String format, final Object[] argArray) {
+ if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, format, LOGGER_CLASS_NAME);
+ rec.setParameters(argArray);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void debug(final String msg, final Throwable t) {
+ if (ALT_DEBUG_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.DEBUG, msg, LOGGER_CLASS_NAME);
+ rec.setThrown(t);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isInfoEnabled() {
+ return logger.isLoggable(Level.INFO);
+ }
+
+ /** {@inheritDoc} */
+ public void info(final String msg) {
+ if (ALT_INFO_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ logger.logRaw(new ExtLogRecord(org.jboss.logmanager.Level.INFO, msg, LOGGER_CLASS_NAME));
+ }
+
+ /** {@inheritDoc} */
+ public void info(final String format, final Object arg) {
+ if (ALT_INFO_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void info(final String format, final Object arg1, final Object arg2) {
+ if (ALT_INFO_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg1, arg2 });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void info(final String format, final Object[] argArray) {
+ if (ALT_INFO_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, format, LOGGER_CLASS_NAME);
+ rec.setParameters(argArray);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void info(final String msg, final Throwable t) {
+ if (ALT_INFO_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.INFO, msg, LOGGER_CLASS_NAME);
+ rec.setThrown(t);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isWarnEnabled() {
+ return logger.isLoggable(Level.WARN);
+ }
+
+ /** {@inheritDoc} */
+ public void warn(final String msg) {
+ if (ALT_WARN_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ logger.logRaw(new ExtLogRecord(org.jboss.logmanager.Level.WARN, msg, LOGGER_CLASS_NAME));
+ }
+
+ /** {@inheritDoc} */
+ public void warn(final String format, final Object arg) {
+ if (ALT_WARN_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void warn(final String format, final Object arg1, final Object arg2) {
+ if (ALT_WARN_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg1, arg2 });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void warn(final String format, final Object[] argArray) {
+ if (ALT_WARN_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, format, LOGGER_CLASS_NAME);
+ rec.setParameters(argArray);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void warn(final String msg, final Throwable t) {
+ if (ALT_WARN_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.WARN, msg, LOGGER_CLASS_NAME);
+ rec.setThrown(t);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public boolean isErrorEnabled() {
+ return logger.isLoggable(Level.ERROR);
+ }
+
+ /** {@inheritDoc} */
+ public void error(final String msg) {
+ if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ logger.logRaw(new ExtLogRecord(org.jboss.logmanager.Level.ERROR, msg, LOGGER_CLASS_NAME));
+ }
+
+ /** {@inheritDoc} */
+ public void error(final String format, final Object arg) {
+ if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void error(final String format, final Object arg1, final Object arg2) {
+ if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, format, LOGGER_CLASS_NAME);
+ rec.setParameters(new Object[] { arg1, arg2 });
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void error(final String format, final Object[] argArray) {
+ if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, format, LOGGER_CLASS_NAME);
+ rec.setParameters(argArray);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ public void error(final String msg, final Throwable t) {
+ if (ALT_ERROR_INT < logger.getEffectiveLevel()) {
+ return;
+ }
+ final ExtLogRecord rec = new ExtLogRecord(org.jboss.logmanager.Level.ERROR, msg, LOGGER_CLASS_NAME);
+ rec.setThrown(t);
+ logger.logRaw(rec);
+ }
+
+ /** {@inheritDoc} */
+ protected Slf4jLogger readResolve() throws ObjectStreamException {
+ return this;
+ }
+}
Modified: jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLoggerFactory.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLoggerFactory.java 2009-06-03 00:45:45 UTC (rev 3212)
+++ jboss-logmanager/trunk/src/main/java/org/slf4j/impl/Slf4jLoggerFactory.java 2009-06-03 23:07:34 UTC (rev 3213)
@@ -25,7 +25,7 @@
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.jboss.logmanager.LogContext;
-import org.jboss.logmanager.Slf4jLogger;
+import org.slf4j.impl.Slf4jLogger;
public final class Slf4jLoggerFactory implements ILoggerFactory {
More information about the jboss-svn-commits
mailing list