From 93e9f097a10899df08a9ab5810322cb7129bfa28 Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Sat, 7 Sep 2019 10:57:35 +0200 Subject: [PATCH] API consolidation --- .../org/slf4j/event/EventRecodingLogger.java | 233 +---- .../src/main/java/org/slf4j/event/Level.java | 58 +- .../org/slf4j/helpers/AbstractLogger.java | 423 ++++++++ .../slf4j/helpers/LegacyAbstractLogger.java | 38 + .../org/slf4j/helpers/MarkerIgnoringBase.java | 1 + .../org/slf4j/helpers/MessageFormatter.java | 38 +- .../org/slf4j/helpers/NamedLoggerBase.java | 1 + .../slf4j/helpers/NormalizedParameters.java | 40 + .../slf4j/helpers/ParameterNormalizer.java | 79 ++ .../org/slf4j/spi/LocationAwareLogger.java | 3 + .../org/slf4j/jul/JDK14LoggerAdapter.java | 916 +++++------------- .../org/slf4j/log4j12/Log4jLoggerAdapter.java | 517 ++-------- .../java/org/slf4j/simple/SimpleLogger.java | 758 ++++++--------- 13 files changed, 1240 insertions(+), 1865 deletions(-) create mode 100644 slf4j-api/src/main/java/org/slf4j/helpers/AbstractLogger.java create mode 100644 slf4j-api/src/main/java/org/slf4j/helpers/LegacyAbstractLogger.java create mode 100644 slf4j-api/src/main/java/org/slf4j/helpers/NormalizedParameters.java create mode 100644 slf4j-api/src/main/java/org/slf4j/helpers/ParameterNormalizer.java diff --git a/slf4j-api/src/main/java/org/slf4j/event/EventRecodingLogger.java b/slf4j-api/src/main/java/org/slf4j/event/EventRecodingLogger.java index afcaf6307..575ca4fed 100755 --- a/slf4j-api/src/main/java/org/slf4j/event/EventRecodingLogger.java +++ b/slf4j-api/src/main/java/org/slf4j/event/EventRecodingLogger.java @@ -2,9 +2,8 @@ import java.util.Queue; -import org.slf4j.Logger; import org.slf4j.Marker; -import org.slf4j.helpers.MessageFormatter; +import org.slf4j.helpers.AbstractLogger; import org.slf4j.helpers.SubstituteLogger; /** @@ -17,7 +16,7 @@ * @author Wessel van Norel * */ -public class EventRecodingLogger implements Logger { +public class EventRecodingLogger extends AbstractLogger { String name; SubstituteLogger logger; @@ -40,272 +39,46 @@ public boolean isTraceEnabled() { return RECORD_ALL_EVENTS; } - public void trace(String msg) { - recordEvent_0Args(Level.TRACE, null, msg, null); - } - - public void trace(String format, Object arg) { - recordEvent_1Args(Level.TRACE, null, format, arg); - } - - public void trace(String format, Object arg1, Object arg2) { - recordEvent2Args(Level.TRACE, null, format, arg1, arg2); - } - - public void trace(String format, Object... arguments) { - recordEventArgArray(Level.TRACE, null, format, arguments); - } - - public void trace(String msg, Throwable t) { - recordEvent_0Args(Level.TRACE, null, msg, t); - } - public boolean isTraceEnabled(Marker marker) { return RECORD_ALL_EVENTS; } - public void trace(Marker marker, String msg) { - recordEvent_0Args(Level.TRACE, marker, msg, null); - } - - public void trace(Marker marker, String format, Object arg) { - recordEvent_1Args(Level.TRACE, marker, format, arg); - } - - public void trace(Marker marker, String format, Object arg1, Object arg2) { - recordEvent2Args(Level.TRACE, marker, format, arg1, arg2); - } - - public void trace(Marker marker, String format, Object... argArray) { - recordEventArgArray(Level.TRACE, marker, format, argArray); - } - - public void trace(Marker marker, String msg, Throwable t) { - recordEvent_0Args(Level.TRACE, marker, msg, t); - } public boolean isDebugEnabled() { return RECORD_ALL_EVENTS; } - public void debug(String msg) { - recordEvent_0Args(Level.DEBUG, null, msg, null); - } - - public void debug(String format, Object arg) { - recordEvent_1Args(Level.DEBUG, null, format, arg); - } - - public void debug(String format, Object arg1, Object arg2) { - recordEvent2Args(Level.DEBUG, null, format, arg1, arg2); - } - - public void debug(String format, Object... arguments) { - recordEventArgArray(Level.DEBUG, null, format, arguments); - } - - public void debug(String msg, Throwable t) { - recordEvent_0Args(Level.DEBUG, null, msg, t); - } - public boolean isDebugEnabled(Marker marker) { return RECORD_ALL_EVENTS; } - public void debug(Marker marker, String msg) { - recordEvent_0Args(Level.DEBUG, marker, msg, null); - } - - public void debug(Marker marker, String format, Object arg) { - recordEvent_1Args(Level.DEBUG, marker, format, arg); - } - - public void debug(Marker marker, String format, Object arg1, Object arg2) { - recordEvent2Args(Level.DEBUG, marker, format, arg1, arg2); - } - - public void debug(Marker marker, String format, Object... arguments) { - recordEventArgArray(Level.DEBUG, marker, format, arguments); - } - - public void debug(Marker marker, String msg, Throwable t) { - recordEvent_0Args(Level.DEBUG, marker, msg, t); - } - public boolean isInfoEnabled() { return RECORD_ALL_EVENTS; } - public void info(String msg) { - recordEvent_0Args(Level.INFO, null, msg, null); - } - - public void info(String format, Object arg) { - recordEvent_1Args(Level.INFO, null, format, arg); - } - - public void info(String format, Object arg1, Object arg2) { - recordEvent2Args(Level.INFO, null, format, arg1, arg2); - } - - public void info(String format, Object... arguments) { - recordEventArgArray(Level.INFO, null, format, arguments); - } - - public void info(String msg, Throwable t) { - recordEvent_0Args(Level.INFO, null, msg, t); - } - public boolean isInfoEnabled(Marker marker) { return RECORD_ALL_EVENTS; } - public void info(Marker marker, String msg) { - recordEvent_0Args(Level.INFO, marker, msg, null); - } - - public void info(Marker marker, String format, Object arg) { - recordEvent_1Args(Level.INFO, marker, format, arg); - } - - public void info(Marker marker, String format, Object arg1, Object arg2) { - recordEvent2Args(Level.INFO, marker, format, arg1, arg2); - } - - public void info(Marker marker, String format, Object... arguments) { - recordEventArgArray(Level.INFO, marker, format, arguments); - } - - public void info(Marker marker, String msg, Throwable t) { - recordEvent_0Args(Level.INFO, marker, msg, t); - - } - public boolean isWarnEnabled() { return RECORD_ALL_EVENTS; } - public void warn(String msg) { - recordEvent_0Args(Level.WARN, null, msg, null); - } - - public void warn(String format, Object arg) { - recordEvent_1Args(Level.WARN, null, format, arg); - } - - public void warn(String format, Object arg1, Object arg2) { - recordEvent2Args(Level.WARN, null, format, arg1, arg2); - } - - public void warn(String format, Object... arguments) { - recordEventArgArray(Level.WARN, null, format, arguments); - } - - public void warn(String msg, Throwable t) { - recordEvent_0Args(Level.WARN, null, msg, t); - } - public boolean isWarnEnabled(Marker marker) { return RECORD_ALL_EVENTS; } - public void warn(Marker marker, String msg) { - recordEvent_0Args(Level.WARN, marker, msg, null); - } - - public void warn(Marker marker, String format, Object arg) { - recordEvent_1Args(Level.WARN, marker, format, arg); - } - - public void warn(Marker marker, String format, Object arg1, Object arg2) { - recordEvent2Args(Level.WARN, marker, format, arg1, arg2); - } - - public void warn(Marker marker, String format, Object... arguments) { - recordEventArgArray(Level.WARN, marker, format, arguments); - } - - public void warn(Marker marker, String msg, Throwable t) { - recordEvent_0Args(Level.WARN, marker, msg, t); - } public boolean isErrorEnabled() { return RECORD_ALL_EVENTS; } - public void error(String msg) { - recordEvent_0Args(Level.ERROR, null, msg, null); - } - - public void error(String format, Object arg) { - recordEvent_1Args(Level.ERROR, null, format, arg); - } - - public void error(String format, Object arg1, Object arg2) { - recordEvent2Args(Level.ERROR, null, format, arg1, arg2); - } - - public void error(String format, Object... arguments) { - recordEventArgArray(Level.ERROR, null, format, arguments); - } - - public void error(String msg, Throwable t) { - recordEvent_0Args(Level.ERROR, null, msg, t); - } - public boolean isErrorEnabled(Marker marker) { return RECORD_ALL_EVENTS; } - public void error(Marker marker, String msg) { - recordEvent_0Args(Level.ERROR, marker, msg, null); - } - - public void error(Marker marker, String format, Object arg) { - recordEvent_1Args(Level.ERROR, marker, format, arg); - } - - public void error(Marker marker, String format, Object arg1, Object arg2) { - recordEvent2Args(Level.ERROR, marker, format, arg1, arg2); - } - - public void error(Marker marker, String format, Object... arguments) { - recordEventArgArray(Level.ERROR, marker, format, arguments); - } - - public void error(Marker marker, String msg, Throwable t) { - recordEvent_0Args(Level.ERROR, marker, msg, t); - } - - private void recordEvent_0Args(Level level, Marker marker, String msg, Throwable t) { - recordEvent(level, marker, msg, null, t); - } - - private void recordEvent_1Args(Level level, Marker marker, String msg, Object arg1) { - recordEvent(level, marker, msg, new Object[] { arg1 }, null); - } - - private void recordEvent2Args(Level level, Marker marker, String msg, Object arg1, Object arg2) { - if (arg2 instanceof Throwable) { - recordEvent(level, marker, msg, new Object[] { arg1 }, (Throwable) arg2); - } else { - recordEvent(level, marker, msg, new Object[] { arg1, arg2 }, null); - } - } - - private void recordEventArgArray(Level level, Marker marker, String msg, Object[] args) { - Throwable throwableCandidate = MessageFormatter.getThrowableCandidate(args); - if (throwableCandidate != null) { - Object[] trimmedCopy = MessageFormatter.trimmedCopy(args); - recordEvent(level, marker, msg, trimmedCopy, throwableCandidate); - } else { - recordEvent(level, marker, msg, args, null); - } - } - - // WARNING: this method assumes that any throwable is properly extracted - private void recordEvent(Level level, Marker marker, String msg, Object[] args, Throwable throwable) { + protected void handleNormalizedLoggingCall(Level level, Marker marker, String msg, Object[] args, Throwable throwable) { SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent(); loggingEvent.setTimeStamp(System.currentTimeMillis()); loggingEvent.setLevel(level); diff --git a/slf4j-api/src/main/java/org/slf4j/event/Level.java b/slf4j-api/src/main/java/org/slf4j/event/Level.java index 2d200bd89..ba3299b72 100755 --- a/slf4j-api/src/main/java/org/slf4j/event/Level.java +++ b/slf4j-api/src/main/java/org/slf4j/event/Level.java @@ -15,25 +15,43 @@ */ public enum Level { - ERROR(ERROR_INT, "ERROR"), WARN(WARN_INT, "WARN"), INFO(INFO_INT, "INFO"), DEBUG(DEBUG_INT, "DEBUG"), TRACE(TRACE_INT, "TRACE"); - - private int levelInt; - private String levelStr; - - Level(int i, String s) { - levelInt = i; - levelStr = s; - } - - public int toInt() { - return levelInt; - } - - /** - * Returns the string representation of this Level. - */ - public String toString() { - return levelStr; - } + ERROR(ERROR_INT, "ERROR"), WARN(WARN_INT, "WARN"), INFO(INFO_INT, "INFO"), DEBUG(DEBUG_INT, "DEBUG"), + TRACE(TRACE_INT, "TRACE"); + + private int levelInt; + private String levelStr; + + Level(int i, String s) { + levelInt = i; + levelStr = s; + } + + public int toInt() { + return levelInt; + } + + public static Level intToLevel(int levelInt) { + switch (levelInt) { + case (TRACE_INT): + return TRACE; + case (DEBUG_INT): + return DEBUG; + case (INFO_INT): + return INFO; + case (WARN_INT): + return WARN; + case (ERROR_INT): + return ERROR; + default: + throw new IllegalArgumentException("Level integer [" + levelInt + "] not recognized."); + } + } + + /** + * Returns the string representation of this Level. + */ + public String toString() { + return levelStr; + } } diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/AbstractLogger.java b/slf4j-api/src/main/java/org/slf4j/helpers/AbstractLogger.java new file mode 100644 index 000000000..a003b00bd --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/helpers/AbstractLogger.java @@ -0,0 +1,423 @@ +/** + * Copyright (c) 2004-2019 QOS.ch + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +package org.slf4j.helpers; + +import java.io.ObjectStreamException; +import java.io.Serializable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.event.Level; + +/** + * An abstract implementation which delegates actual logging work to the + * {@link #handleNormalizedLoggingCall(Level, Marker, String, Object[], Throwable)} method. + * + * @author Ceki Gülcü + * @since 2.0 + */ +public abstract class AbstractLogger implements Logger, Serializable { + + private static final long serialVersionUID = -2529255052481744503L; + + protected String name; + + public String getName() { + return name; + } + + /** + * Replace this instance with a homonymous (same name) logger returned + * by LoggerFactory. Note that this method is only called during + * deserialization. + * + *

+ * This approach will work well if the desired ILoggerFactory is the one + * references by LoggerFactory. However, if the user manages its logger hierarchy + * through a different (non-static) mechanism, e.g. dependency injection, then + * this approach would be mostly counterproductive. + * + * @return logger with same name as returned by LoggerFactory + * @throws ObjectStreamException + */ + protected Object readResolve() throws ObjectStreamException { + // using getName() instead of this.name works even for + // NOPLogger + return LoggerFactory.getLogger(getName()); + } + + @Override + public void trace(String msg) { + if (isTraceEnabled()) { + handle_0ArgsCall(Level.TRACE, null, msg, null); + } + } + + @Override + public void trace(String format, Object arg) { + if (isTraceEnabled()) { + handle_1ArgsCall(Level.TRACE, null, format, arg); + } + } + + @Override + public void trace(String format, Object arg1, Object arg2) { + if (isTraceEnabled()) { + handle2ArgsCall(Level.TRACE, null, format, arg1, arg2); + } + } + + @Override + public void trace(String format, Object... arguments) { + if (isTraceEnabled()) { + handleArgArrayCall(Level.TRACE, null, format, arguments); + } + } + + @Override + public void trace(String msg, Throwable t) { + if (isTraceEnabled()) { + handle_0ArgsCall(Level.TRACE, null, msg, t); + } + } + + @Override + public void trace(Marker marker, String msg) { + if (isTraceEnabled(marker)) { + handle_0ArgsCall(Level.TRACE, marker, msg, null); + } + } + + @Override + public void trace(Marker marker, String format, Object arg) { + if (isTraceEnabled(marker)) { + handle_1ArgsCall(Level.TRACE, marker, format, arg); + } + } + + @Override + public void trace(Marker marker, String format, Object arg1, Object arg2) { + if (isTraceEnabled(marker)) { + handle2ArgsCall(Level.TRACE, marker, format, arg1, arg2); + } + } + + @Override + public void trace(Marker marker, String format, Object... argArray) { + if (isTraceEnabled(marker)) { + handleArgArrayCall(Level.TRACE, marker, format, argArray); + } + } + + public void trace(Marker marker, String msg, Throwable t) { + if (isTraceEnabled(marker)) { + handle_0ArgsCall(Level.TRACE, marker, msg, t); + } + } + + public void debug(String msg) { + if (isDebugEnabled()) { + handle_0ArgsCall(Level.DEBUG, null, msg, null); + } + } + + public void debug(String format, Object arg) { + if (isDebugEnabled()) { + handle_1ArgsCall(Level.DEBUG, null, format, arg); + } + } + + public void debug(String format, Object arg1, Object arg2) { + if (isDebugEnabled()) { + handle2ArgsCall(Level.DEBUG, null, format, arg1, arg2); + } + } + + public void debug(String format, Object... arguments) { + if (isDebugEnabled()) { + handleArgArrayCall(Level.DEBUG, null, format, arguments); + } + } + + public void debug(String msg, Throwable t) { + if (isDebugEnabled()) { + handle_0ArgsCall(Level.DEBUG, null, msg, t); + } + } + + public void debug(Marker marker, String msg) { + if (isDebugEnabled(marker)) { + handle_0ArgsCall(Level.DEBUG, marker, msg, null); + } + } + + public void debug(Marker marker, String format, Object arg) { + if (isDebugEnabled(marker)) { + handle_1ArgsCall(Level.DEBUG, marker, format, arg); + } + } + + public void debug(Marker marker, String format, Object arg1, Object arg2) { + if (isDebugEnabled(marker)) { + handle2ArgsCall(Level.DEBUG, marker, format, arg1, arg2); + } + } + + public void debug(Marker marker, String format, Object... arguments) { + if (isDebugEnabled(marker)) { + handleArgArrayCall(Level.DEBUG, marker, format, arguments); + } + } + + public void debug(Marker marker, String msg, Throwable t) { + if (isDebugEnabled(marker)) { + handle_0ArgsCall(Level.DEBUG, marker, msg, t); + } + } + + public void info(String msg) { + if (isInfoEnabled()) { + handle_0ArgsCall(Level.INFO, null, msg, null); + } + } + + public void info(String format, Object arg) { + if (isInfoEnabled()) { + handle_1ArgsCall(Level.INFO, null, format, arg); + } + } + + public void info(String format, Object arg1, Object arg2) { + if (isInfoEnabled()) { + handle2ArgsCall(Level.INFO, null, format, arg1, arg2); + } + } + + public void info(String format, Object... arguments) { + if (isInfoEnabled()) { + handleArgArrayCall(Level.INFO, null, format, arguments); + } + } + + public void info(String msg, Throwable t) { + if (isInfoEnabled()) { + handle_0ArgsCall(Level.INFO, null, msg, t); + } + } + + public void info(Marker marker, String msg) { + if (isInfoEnabled(marker)) { + handle_0ArgsCall(Level.INFO, marker, msg, null); + } + } + + public void info(Marker marker, String format, Object arg) { + if (isInfoEnabled(marker)) { + handle_1ArgsCall(Level.INFO, marker, format, arg); + } + } + + public void info(Marker marker, String format, Object arg1, Object arg2) { + if (isInfoEnabled(marker)) { + handle2ArgsCall(Level.INFO, marker, format, arg1, arg2); + } + } + + public void info(Marker marker, String format, Object... arguments) { + if (isInfoEnabled(marker)) { + handleArgArrayCall(Level.INFO, marker, format, arguments); + } + } + + public void info(Marker marker, String msg, Throwable t) { + if (isInfoEnabled(marker)) { + handle_0ArgsCall(Level.INFO, marker, msg, t); + } + } + + public void warn(String msg) { + if (isWarnEnabled()) { + handle_0ArgsCall(Level.WARN, null, msg, null); + } + } + + public void warn(String format, Object arg) { + if (isWarnEnabled()) { + handle_1ArgsCall(Level.WARN, null, format, arg); + } + } + + public void warn(String format, Object arg1, Object arg2) { + if (isWarnEnabled()) { + handle2ArgsCall(Level.WARN, null, format, arg1, arg2); + } + } + + public void warn(String format, Object... arguments) { + if (isWarnEnabled()) { + handleArgArrayCall(Level.WARN, null, format, arguments); + } + } + + public void warn(String msg, Throwable t) { + if (isWarnEnabled()) { + handle_0ArgsCall(Level.WARN, null, msg, t); + } + } + + public void warn(Marker marker, String msg) { + if (isWarnEnabled(marker)) { + handle_0ArgsCall(Level.WARN, marker, msg, null); + } + } + + public void warn(Marker marker, String format, Object arg) { + if (isWarnEnabled(marker)) { + handle_1ArgsCall(Level.WARN, marker, format, arg); + } + } + + public void warn(Marker marker, String format, Object arg1, Object arg2) { + if (isWarnEnabled(marker)) { + handle2ArgsCall(Level.WARN, marker, format, arg1, arg2); + } + } + + public void warn(Marker marker, String format, Object... arguments) { + if (isWarnEnabled(marker)) { + handleArgArrayCall(Level.WARN, marker, format, arguments); + } + } + + public void warn(Marker marker, String msg, Throwable t) { + if (isWarnEnabled(marker)) { + handle_0ArgsCall(Level.WARN, marker, msg, t); + } + } + + public void error(String msg) { + if (isErrorEnabled()) { + handle_0ArgsCall(Level.ERROR, null, msg, null); + } + } + + public void error(String format, Object arg) { + if (isErrorEnabled()) { + handle_1ArgsCall(Level.ERROR, null, format, arg); + } + } + + public void error(String format, Object arg1, Object arg2) { + if (isErrorEnabled()) { + handle2ArgsCall(Level.ERROR, null, format, arg1, arg2); + } + } + + public void error(String format, Object... arguments) { + if (isErrorEnabled()) { + handleArgArrayCall(Level.ERROR, null, format, arguments); + } + } + + public void error(String msg, Throwable t) { + if (isErrorEnabled()) { + handle_0ArgsCall(Level.ERROR, null, msg, t); + } + } + + public void error(Marker marker, String msg) { + if (isErrorEnabled(marker)) { + handle_0ArgsCall(Level.ERROR, marker, msg, null); + } + } + + public void error(Marker marker, String format, Object arg) { + if (isErrorEnabled(marker)) { + handle_1ArgsCall(Level.ERROR, marker, format, arg); + } + } + + public void error(Marker marker, String format, Object arg1, Object arg2) { + if (isErrorEnabled(marker)) { + handle2ArgsCall(Level.ERROR, marker, format, arg1, arg2); + } + } + + public void error(Marker marker, String format, Object... arguments) { + if (isErrorEnabled(marker)) { + handleArgArrayCall(Level.ERROR, marker, format, arguments); + } + } + + public void error(Marker marker, String msg, Throwable t) { + if (isErrorEnabled(marker)) { + handle_0ArgsCall(Level.ERROR, marker, msg, t); + } + } + + private void handle_0ArgsCall(Level level, Marker marker, String msg, Throwable t) { + handleNormalizedLoggingCall(level, marker, msg, null, t); + } + + private void handle_1ArgsCall(Level level, Marker marker, String msg, Object arg1) { + handleNormalizedLoggingCall(level, marker, msg, new Object[] { arg1 }, null); + } + + private void handle2ArgsCall(Level level, Marker marker, String msg, Object arg1, Object arg2) { + if (arg2 instanceof Throwable) { + handleNormalizedLoggingCall(level, marker, msg, new Object[] { arg1 }, (Throwable) arg2); + } else { + handleNormalizedLoggingCall(level, marker, msg, new Object[] { arg1, arg2 }, null); + } + } + + private void handleArgArrayCall(Level level, Marker marker, String msg, Object[] args) { + Throwable throwableCandidate = MessageFormatter.getThrowableCandidate(args); + if (throwableCandidate != null) { + Object[] trimmedCopy = MessageFormatter.trimmedCopy(args); + handleNormalizedLoggingCall(level, marker, msg, trimmedCopy, throwableCandidate); + } else { + handleNormalizedLoggingCall(level, marker, msg, args, null); + } + } + + abstract protected String getFullyQualifiedCallerName(); + + /** + * Given various arguments passed as parameters perform actual logging. + * + *

This method assumes that the separation of the args array into actual + * objects and a throwable has been already operated. + * + * @param level + * @param marker + * @param msg + * @param arguments + * @param throwable + */ + abstract protected void handleNormalizedLoggingCall(Level level, Marker marker, String msg, Object[] arguments, Throwable throwable); + +} diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/LegacyAbstractLogger.java b/slf4j-api/src/main/java/org/slf4j/helpers/LegacyAbstractLogger.java new file mode 100644 index 000000000..7c8abf3ce --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/helpers/LegacyAbstractLogger.java @@ -0,0 +1,38 @@ +package org.slf4j.helpers; + +import org.slf4j.Marker; + +abstract public class LegacyAbstractLogger extends AbstractLogger { + + + + private static final long serialVersionUID = -7041884104854048950L; + + @Override + public boolean isTraceEnabled(Marker marker) { + return isTraceEnabled(); + } + + + @Override + public boolean isDebugEnabled(Marker marker) { + return isDebugEnabled(); + } + + @Override + public boolean isInfoEnabled(Marker marker) { + return isInfoEnabled(); + } + + @Override + public boolean isWarnEnabled(Marker marker) { + return isWarnEnabled(); + } + + @Override + public boolean isErrorEnabled(Marker marker) { + return isErrorEnabled(); + } + + +} diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/MarkerIgnoringBase.java b/slf4j-api/src/main/java/org/slf4j/helpers/MarkerIgnoringBase.java index dd7653841..715cec75c 100644 --- a/slf4j-api/src/main/java/org/slf4j/helpers/MarkerIgnoringBase.java +++ b/slf4j-api/src/main/java/org/slf4j/helpers/MarkerIgnoringBase.java @@ -34,6 +34,7 @@ * any marker data passed as argument. * * @author Ceki Gulcu + * @deprecated */ public abstract class MarkerIgnoringBase extends NamedLoggerBase implements Logger { diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java index 09a55f443..461bcb680 100755 --- a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java +++ b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java @@ -161,6 +161,17 @@ final public static FormattingTuple arrayFormat(final String messagePattern, fin return arrayFormat(messagePattern, args, throwableCandidate); } + /** + * Assumes that argArray only contains arguments with no throwable as last element. + * + * @param messagePattern + * @param argArray + */ + final public static String basicArrayFormat(final String messagePattern, final Object[] argArray) { + FormattingTuple ft = arrayFormat(messagePattern, argArray, null); + return ft.getMessage(); + } + final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray, Throwable throwable) { if (messagePattern == null) { @@ -398,18 +409,9 @@ private static void doubleArrayAppend(StringBuilder sbuf, double[] a) { * otherwise it returns null */ public static Throwable getThrowableCandidate(final Object[] argArray) { - if (argArray == null || argArray.length == 0) { - return null; - } - - final Object lastEntry = argArray[argArray.length - 1]; - if (lastEntry instanceof Throwable) { - return (Throwable) lastEntry; - } + return ParameterNormalizer.getThrowableCandidate(argArray); + } - return null; - } - /** * Helper method to get all but the last element of an array * @@ -419,19 +421,7 @@ public static Throwable getThrowableCandidate(final Object[] argArray) { * @return a copy of the array without the last element */ public static Object[] trimmedCopy(final Object[] argArray) { - if (argArray == null || argArray.length == 0) { - throw new IllegalStateException("non-sensical empty or null argument array"); - } - - final int trimmedLen = argArray.length - 1; - - Object[] trimmed = new Object[trimmedLen]; - - if (trimmedLen > 0) { - System.arraycopy(argArray, 0, trimmed, 0, trimmedLen); - } - - return trimmed; + return ParameterNormalizer.trimmedCopy(argArray); } } diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/NamedLoggerBase.java b/slf4j-api/src/main/java/org/slf4j/helpers/NamedLoggerBase.java index e2a1d068d..326c07db0 100644 --- a/slf4j-api/src/main/java/org/slf4j/helpers/NamedLoggerBase.java +++ b/slf4j-api/src/main/java/org/slf4j/helpers/NamedLoggerBase.java @@ -37,6 +37,7 @@ * @author Ceki Gulcu * @see #readResolve * @since 1.5.3 + * @deprecated */ abstract class NamedLoggerBase implements Logger, Serializable { diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/NormalizedParameters.java b/slf4j-api/src/main/java/org/slf4j/helpers/NormalizedParameters.java new file mode 100644 index 000000000..900e4e003 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/helpers/NormalizedParameters.java @@ -0,0 +1,40 @@ +package org.slf4j.helpers; + +/** + * Holds normalized calling call parameters. + * + * @author ceki + * @since 2.0 + */ +public class NormalizedParameters { + + + final String message; + final Object[] arguments; + final Throwable throwable; + + public NormalizedParameters(String message, Object[] arguments, Throwable throwable) { + this.message = message; + this.arguments = arguments; + this.throwable = throwable; + } + + public NormalizedParameters(String message, Object[] arguments) { + this(message, arguments, null); + } + + public String getMessage() { + return message; + } + + public Object[] getArguments() { + return arguments; + } + + public Throwable getThrowable() { + return throwable; + } + + + +} diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/ParameterNormalizer.java b/slf4j-api/src/main/java/org/slf4j/helpers/ParameterNormalizer.java new file mode 100644 index 000000000..83a133c67 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/helpers/ParameterNormalizer.java @@ -0,0 +1,79 @@ +package org.slf4j.helpers; + +/** + * This class serves to normalize logging call invocation parameters. + * + * More specifically, if a throwable argument is not supplied directly, it + * attempts to extract it from the argument array. + * + * @author ceki + * @since 2.0 + */ +public class ParameterNormalizer { + + public static NormalizedParameters normalize(String msg, Object[] arguments, Throwable t) { + + if (t != null) { + return new NormalizedParameters(msg, arguments, t); + } + + if (arguments == null || arguments.length == 0) { + return new NormalizedParameters(msg, arguments, t); + } + + Throwable throwableCandidate = getThrowableCandidate(arguments); + if (throwableCandidate != null) { + Object[] trimmedArguments = MessageFormatter.trimmedCopy(arguments); + return new NormalizedParameters(msg, trimmedArguments, throwableCandidate); + } else { + return new NormalizedParameters(msg, arguments); + } + + } + + /** + * Helper method to determine if an {@link Object} array contains a + * {@link Throwable} as last element + * + * @param argArray The arguments off which we want to know if it contains a + * {@link Throwable} as last element + * @return if the last {@link Object} in argArray is a {@link Throwable} this + * method will return it, otherwise it returns null + */ + public static Throwable getThrowableCandidate(final Object[] argArray) { + if (argArray == null || argArray.length == 0) { + return null; + } + + final Object lastEntry = argArray[argArray.length - 1]; + if (lastEntry instanceof Throwable) { + return (Throwable) lastEntry; + } + + return null; + } + + /** + * Helper method to get all but the last element of an array + * + * @param argArray The arguments from which we want to remove the last element + * + * @return a copy of the array without the last element + */ + public static Object[] trimmedCopy(final Object[] argArray) { + if (argArray == null || argArray.length == 0) { + throw new IllegalStateException("non-sensical empty or null argument array"); + } + + final int trimmedLen = argArray.length - 1; + + Object[] trimmed = new Object[trimmedLen]; + + if (trimmedLen > 0) { + System.arraycopy(argArray, 0, trimmed, 0, trimmedLen); + } + + return trimmed; + } + +} diff --git a/slf4j-api/src/main/java/org/slf4j/spi/LocationAwareLogger.java b/slf4j-api/src/main/java/org/slf4j/spi/LocationAwareLogger.java index 074d670a8..c630e6078 100644 --- a/slf4j-api/src/main/java/org/slf4j/spi/LocationAwareLogger.java +++ b/slf4j-api/src/main/java/org/slf4j/spi/LocationAwareLogger.java @@ -51,9 +51,12 @@ public interface LocationAwareLogger extends Logger { * Printing method with support for location information. * * @param marker The marker to be used for this event, may be null. + * * @param fqcn The fully qualified class name of the logger instance, * typically the logger class, logger bridge or a logger wrapper. + * * @param level One of the level integers defined in this interface + * * @param message The message for the log event * @param t Throwable associated with the log event, may be null. */ diff --git a/slf4j-jdk14/src/main/java/org/slf4j/jul/JDK14LoggerAdapter.java b/slf4j-jdk14/src/main/java/org/slf4j/jul/JDK14LoggerAdapter.java index 32b5fb5f3..92c76b8ae 100755 --- a/slf4j-jdk14/src/main/java/org/slf4j/jul/JDK14LoggerAdapter.java +++ b/slf4j-jdk14/src/main/java/org/slf4j/jul/JDK14LoggerAdapter.java @@ -31,9 +31,12 @@ import org.slf4j.Marker; import org.slf4j.event.EventConstants; import org.slf4j.event.LoggingEvent; +import org.slf4j.helpers.AbstractLogger; import org.slf4j.helpers.FormattingTuple; -import org.slf4j.helpers.MarkerIgnoringBase; +import org.slf4j.helpers.LegacyAbstractLogger; import org.slf4j.helpers.MessageFormatter; +import org.slf4j.helpers.NormalizedParameters; +import org.slf4j.helpers.ParameterNormalizer; import org.slf4j.helpers.SubstituteLogger; import org.slf4j.spi.LocationAwareLogger; @@ -46,667 +49,258 @@ * @author Ceki Gülcü * @author Peter Royal */ -public final class JDK14LoggerAdapter extends MarkerIgnoringBase implements LocationAwareLogger { - - private static final long serialVersionUID = -8053026990503422791L; - - transient final java.util.logging.Logger logger; - - // WARN: JDK14LoggerAdapter constructor should have only package access so - // that only JDK14LoggerFactory be able to create one. - JDK14LoggerAdapter(java.util.logging.Logger logger) { - this.logger = logger; - this.name = logger.getName(); - } - - /** - * Is this logger instance enabled for the FINEST level? - * - * @return True if this Logger is enabled for level FINEST, false otherwise. - */ - public boolean isTraceEnabled() { - return logger.isLoggable(Level.FINEST); - } - - /** - * Log a message object at level FINEST. - * - * @param msg - * - the message object to be logged - */ - public void trace(String msg) { - if (logger.isLoggable(Level.FINEST)) { - log(SELF, Level.FINEST, msg, null); - } - } - - /** - * Log a message at level FINEST according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for level FINEST. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void trace(String format, Object arg) { - if (logger.isLoggable(Level.FINEST)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level FINEST according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the FINEST level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void trace(String format, Object arg1, Object arg2) { - if (logger.isLoggable(Level.FINEST)) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level FINEST according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the FINEST level. - * - * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - public void trace(String format, Object... argArray) { - if (logger.isLoggable(Level.FINEST)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - log(SELF, Level.FINEST, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at level FINEST with an accompanying message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void trace(String msg, Throwable t) { - if (logger.isLoggable(Level.FINEST)) { - log(SELF, Level.FINEST, msg, t); - } - } - - /** - * Is this logger instance enabled for the FINE level? - * - * @return True if this Logger is enabled for level FINE, false otherwise. - */ - public boolean isDebugEnabled() { - return logger.isLoggable(Level.FINE); - } - - /** - * Log a message object at level FINE. - * - * @param msg - * - the message object to be logged - */ - public void debug(String msg) { - if (logger.isLoggable(Level.FINE)) { - log(SELF, Level.FINE, msg, null); - } - } - - /** - * Log a message at level FINE according to the specified format and argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for level FINE. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void debug(String format, Object arg) { - if (logger.isLoggable(Level.FINE)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level FINE according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the FINE level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void debug(String format, Object arg1, Object arg2) { - if (logger.isLoggable(Level.FINE)) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level FINE according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the FINE level. - * - * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - public void debug(String format, Object... argArray) { - if (logger.isLoggable(Level.FINE)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - log(SELF, Level.FINE, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at level FINE with an accompanying message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void debug(String msg, Throwable t) { - if (logger.isLoggable(Level.FINE)) { - log(SELF, Level.FINE, msg, t); - } - } - - /** - * Is this logger instance enabled for the INFO level? - * - * @return True if this Logger is enabled for the INFO level, false otherwise. - */ - public boolean isInfoEnabled() { - return logger.isLoggable(Level.INFO); - } - - /** - * Log a message object at the INFO level. - * - * @param msg - * - the message object to be logged - */ - public void info(String msg) { - if (logger.isLoggable(Level.INFO)) { - log(SELF, Level.INFO, msg, null); - } - } - - /** - * Log a message at level INFO according to the specified format and argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void info(String format, Object arg) { - if (logger.isLoggable(Level.INFO)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the INFO level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void info(String format, Object arg1, Object arg2) { - if (logger.isLoggable(Level.INFO)) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level INFO according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - * - * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - public void info(String format, Object... argArray) { - if (logger.isLoggable(Level.INFO)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - log(SELF, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the INFO level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void info(String msg, Throwable t) { - if (logger.isLoggable(Level.INFO)) { - log(SELF, Level.INFO, msg, t); - } - } - - /** - * Is this logger instance enabled for the WARNING level? - * - * @return True if this Logger is enabled for the WARNING level, false - * otherwise. - */ - public boolean isWarnEnabled() { - return logger.isLoggable(Level.WARNING); - } - - /** - * Log a message object at the WARNING level. - * - * @param msg - * - the message object to be logged - */ - public void warn(String msg) { - if (logger.isLoggable(Level.WARNING)) { - log(SELF, Level.WARNING, msg, null); - } - } - - /** - * Log a message at the WARNING level according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARNING level. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void warn(String format, Object arg) { - if (logger.isLoggable(Level.WARNING)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the WARNING level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARNING level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void warn(String format, Object arg1, Object arg2) { - if (logger.isLoggable(Level.WARNING)) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level WARNING according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARNING level. - * - * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - public void warn(String format, Object... argArray) { - if (logger.isLoggable(Level.WARNING)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - log(SELF, Level.WARNING, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the WARNING level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void warn(String msg, Throwable t) { - if (logger.isLoggable(Level.WARNING)) { - log(SELF, Level.WARNING, msg, t); - } - } - - /** - * Is this logger instance enabled for level SEVERE? - * - * @return True if this Logger is enabled for level SEVERE, false otherwise. - */ - public boolean isErrorEnabled() { - return logger.isLoggable(Level.SEVERE); - } - - /** - * Log a message object at the SEVERE level. - * - * @param msg - * - the message object to be logged - */ - public void error(String msg) { - if (logger.isLoggable(Level.SEVERE)) { - log(SELF, Level.SEVERE, msg, null); - } - } - - /** - * Log a message at the SEVERE level according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the SEVERE level. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void error(String format, Object arg) { - if (logger.isLoggable(Level.SEVERE)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the SEVERE level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the SEVERE level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void error(String format, Object arg1, Object arg2) { - if (logger.isLoggable(Level.SEVERE)) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level SEVERE according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the SEVERE level. - * - * - * @param format - * the format string - * @param arguments - * an array of arguments - */ - public void error(String format, Object... arguments) { - if (logger.isLoggable(Level.SEVERE)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - log(SELF, Level.SEVERE, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the SEVERE level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void error(String msg, Throwable t) { - if (logger.isLoggable(Level.SEVERE)) { - log(SELF, Level.SEVERE, msg, t); - } - } - - /** - * Log the message at the specified level with the specified throwable if any. - * This method creates a LogRecord and fills in caller date before calling - * this instance's JDK14 logger. - * - * See bug report #13 for more details. - * - * @param level - * @param msg - * @param t - */ - private void log(String callerFQCN, Level level, String msg, Throwable t) { - // millis and thread are filled by the constructor - LogRecord record = new LogRecord(level, msg); - record.setLoggerName(getName()); - record.setThrown(t); - // Note: parameters in record are not set because SLF4J only - // supports a single formatting style - fillCallerData(callerFQCN, record); - logger.log(record); - } - - static String SELF = JDK14LoggerAdapter.class.getName(); - static String SUPER = MarkerIgnoringBase.class.getName(); - static String SUBSTITUE = SubstituteLogger.class.getName(); - - static String BARRIER_CLASSES[] = new String[] {SELF, SUPER, SUBSTITUE}; - - /** - * Fill in caller data if possible. - * - * @param record - * The record to update - */ +public final class JDK14LoggerAdapter extends LegacyAbstractLogger implements LocationAwareLogger { + + private static final long serialVersionUID = -8053026990503422791L; + + transient final java.util.logging.Logger logger; + + // WARN: JDK14LoggerAdapter constructor should have only package access so + // that only JDK14LoggerFactory be able to create one. + JDK14LoggerAdapter(java.util.logging.Logger logger) { + this.logger = logger; + this.name = logger.getName(); + } + + /** + * Is this logger instance enabled for the FINEST level? + * + * @return True if this Logger is enabled for level FINEST, false otherwise. + */ + public boolean isTraceEnabled() { + return logger.isLoggable(Level.FINEST); + } + + /** + * Is this logger instance enabled for the FINE level? + * + * @return True if this Logger is enabled for level FINE, false otherwise. + */ + public boolean isDebugEnabled() { + return logger.isLoggable(Level.FINE); + } + + /** + * Is this logger instance enabled for the INFO level? + * + * @return True if this Logger is enabled for the INFO level, false otherwise. + */ + public boolean isInfoEnabled() { + return logger.isLoggable(Level.INFO); + } + + /** + * Is this logger instance enabled for the WARNING level? + * + * @return True if this Logger is enabled for the WARNING level, false + * otherwise. + */ + public boolean isWarnEnabled() { + return logger.isLoggable(Level.WARNING); + } + + /** + * Is this logger instance enabled for level SEVERE? + * + * @return True if this Logger is enabled for level SEVERE, false otherwise. + */ + public boolean isErrorEnabled() { + return logger.isLoggable(Level.SEVERE); + } + +// /** +// * Log the message at the specified level with the specified throwable if any. +// * This method creates a LogRecord and fills in caller date before calling +// * this instance's JDK14 logger. +// * +// * See bug report #13 for more details. +// * +// * @param level +// * @param msg +// * @param t +// */ +// private void log(String callerFQCN, Level level, String msg, Throwable t) { +// // millis and thread are filled by the constructor +// LogRecord record = new LogRecord(level, msg); +// record.setLoggerName(getName()); +// record.setThrown(t); +// // Note: parameters in record are not set because SLF4J only +// // supports a single formatting style +// fillCallerData(callerFQCN, record); +// logger.log(record); +// } + + /** + * Log the message at the specified level with the specified throwable if any. + * This method creates a LogRecord and fills in caller date before calling this + * instance's JDK14 logger. + */ + @Override + protected void handleNormalizedLoggingCall(org.slf4j.event.Level level, Marker marker, String msg, Object[] args, + Throwable throwable) { + innerNormalizedLoggingCallHandler(getFullyQualifiedCallerName(), level, marker, msg, args, throwable); + } + + + private void innerNormalizedLoggingCallHandler(String fqcn, org.slf4j.event.Level level, Marker marker, String msg, Object[] args, + Throwable throwable) { + // millis and thread are filled by the constructor + Level julLevel = slf4jLevelToJULLevel(level); + String formattedMessage = MessageFormatter.basicArrayFormat(msg, args); + LogRecord record = new LogRecord(julLevel, formattedMessage); + + // https://jira.qos.ch/browse/SLF4J-13 + record.setLoggerName(getName()); + record.setThrown(throwable); + // Note: parameters in record are not set because SLF4J only + // supports a single formatting style + // See also https://jira.qos.ch/browse/SLF4J-10 + fillCallerData(fqcn, record); + logger.log(record); + } + + + @Override + protected String getFullyQualifiedCallerName() { + return SELF; + } + + + @Override + public void log(Marker marker, String callerFQCN, int slf4jLevelInt, String message, Object[] arguments, + Throwable throwable) { + + org.slf4j.event.Level slf4jLevel = org.slf4j.event.Level.intToLevel(slf4jLevelInt); + Level julLevel = slf4jLevelIntToJULLevel(slf4jLevelInt); + + if (logger.isLoggable(julLevel)) { + NormalizedParameters np = ParameterNormalizer.normalize(message, arguments, throwable); + innerNormalizedLoggingCallHandler(callerFQCN, slf4jLevel, marker, np.getMessage(), np.getArguments(), np.getThrowable()); + } + } + + + /** + * Fill in caller data if possible. + * + * @param record The record to update + */ final private void fillCallerData(String callerFQCN, LogRecord record) { - StackTraceElement[] steArray = new Throwable().getStackTrace(); - - int selfIndex = -1; - for (int i = 0; i < steArray.length; i++) { - final String className = steArray[i].getClassName(); - - if (barrierMatch(callerFQCN, className)) { - selfIndex = i; - break; - } - } - - int found = -1; - for (int i = selfIndex + 1; i < steArray.length; i++) { - final String className = steArray[i].getClassName(); - if (!(barrierMatch(callerFQCN, className))) { - found = i; - break; - } - } - - if (found != -1) { - StackTraceElement ste = steArray[found]; - // setting the class name has the side effect of setting - // the needToInferCaller variable to false. - record.setSourceClassName(ste.getClassName()); - record.setSourceMethodName(ste.getMethodName()); - } - } - - private boolean barrierMatch(String callerFQCN, String candidateClassName) { - if(candidateClassName.equals(callerFQCN)) - return true; - for(String barrierClassName: BARRIER_CLASSES) { - if(barrierClassName.equals(candidateClassName)) { - return true; - } - } - return false; + StackTraceElement[] steArray = new Throwable().getStackTrace(); + + int selfIndex = -1; + for (int i = 0; i < steArray.length; i++) { + final String className = steArray[i].getClassName(); + + if (barrierMatch(callerFQCN, className)) { + selfIndex = i; + break; + } + } + + int found = -1; + for (int i = selfIndex + 1; i < steArray.length; i++) { + final String className = steArray[i].getClassName(); + if (!(barrierMatch(callerFQCN, className))) { + found = i; + break; + } + } + + if (found != -1) { + StackTraceElement ste = steArray[found]; + // setting the class name has the side effect of setting + // the needToInferCaller variable to false. + record.setSourceClassName(ste.getClassName()); + record.setSourceMethodName(ste.getMethodName()); + } + } + + static String SELF = JDK14LoggerAdapter.class.getName(); + + static String SUPER = LegacyAbstractLogger.class.getName(); + static String SUPER_OF_SUPER = AbstractLogger.class.getName(); + static String SUBSTITUE = SubstituteLogger.class.getName(); + + static String BARRIER_CLASSES[] = new String[] { SUPER_OF_SUPER, SUPER, SELF, SUBSTITUE }; + + private boolean barrierMatch(String callerFQCN, String candidateClassName) { + if (candidateClassName.equals(callerFQCN)) + return true; + for (String barrierClassName : BARRIER_CLASSES) { + if (barrierClassName.equals(candidateClassName)) { + return true; + } + } + return false; + } + + + private static Level slf4jLevelIntToJULLevel(int levelInt) { + org.slf4j.event.Level slf4jLevel = org.slf4j.event.Level.intToLevel(levelInt); + return slf4jLevelToJULLevel(slf4jLevel); + } + + private static Level slf4jLevelToJULLevel(org.slf4j.event.Level slf4jLevel) { + Level julLevel; + switch (slf4jLevel) { + case TRACE: + julLevel = Level.FINEST; + break; + case DEBUG: + julLevel = Level.FINE; + break; + case INFO: + julLevel = Level.INFO; + break; + case WARN: + julLevel = Level.WARNING; + break; + case ERROR: + julLevel = Level.SEVERE; + break; + default: + throw new IllegalStateException("Level " + slf4jLevel + " is not recognized."); + } + return julLevel; + } + + /** + * @since 1.7.15 + */ + public void log(LoggingEvent event) { + // assumes that the invocation is made from a substitute logger + // this assumption might change in the future with the advent of a fluent API + Level julLevel = slf4jLevelToJULLevel(event.getLevel()); + if (logger.isLoggable(julLevel)) { + LogRecord record = eventToRecord(event, julLevel); + logger.log(record); + } + } + + private LogRecord eventToRecord(LoggingEvent event, Level julLevel) { + String format = event.getMessage(); + Object[] arguments = event.getArgumentArray(); + FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); + if (ft.getThrowable() != null && event.getThrowable() != null) { + throw new IllegalArgumentException( + "both last element in argument array and last argument are of type Throwable"); + } + + Throwable t = event.getThrowable(); + if (ft.getThrowable() != null) { + t = ft.getThrowable(); + throw new IllegalStateException("fix above code"); + } + + LogRecord record = new LogRecord(julLevel, ft.getMessage()); + record.setLoggerName(event.getLoggerName()); + record.setMillis(event.getTimeStamp()); + record.setSourceClassName(EventConstants.NA_SUBST); + record.setSourceMethodName(EventConstants.NA_SUBST); + + record.setThrown(t); + return record; } - public void log(Marker marker, String callerFQCN, int level, String message, Object[] argArray, Throwable t) { - Level julLevel = slf4jLevelIntToJULLevel(level); - // the logger.isLoggable check avoids the unconditional - // construction of location data for disabled log - // statements. As of 2008-07-31, callers of this method - // do not perform this check. See also - // http://jira.qos.ch/browse/SLF4J-81 - if (logger.isLoggable(julLevel)) { - log(callerFQCN, julLevel, message, t); - } - } - - private Level slf4jLevelIntToJULLevel(int slf4jLevelInt) { - Level julLevel; - switch (slf4jLevelInt) { - case LocationAwareLogger.TRACE_INT: - julLevel = Level.FINEST; - break; - case LocationAwareLogger.DEBUG_INT: - julLevel = Level.FINE; - break; - case LocationAwareLogger.INFO_INT: - julLevel = Level.INFO; - break; - case LocationAwareLogger.WARN_INT: - julLevel = Level.WARNING; - break; - case LocationAwareLogger.ERROR_INT: - julLevel = Level.SEVERE; - break; - default: - throw new IllegalStateException("Level number " + slf4jLevelInt + " is not recognized."); - } - return julLevel; - } - - /** - * @since 1.7.15 - */ - public void log(LoggingEvent event) { - // assumes that the invocation is made from a substitute logger - // this assumption might change in the future with the advent of a fluent API - Level julLevel = slf4jLevelIntToJULLevel(event.getLevel().toInt()); - if (logger.isLoggable(julLevel)) { - LogRecord record = eventToRecord(event, julLevel); - logger.log(record); - } - } - - private LogRecord eventToRecord(LoggingEvent event, Level julLevel) { - String format = event.getMessage(); - Object[] arguments = event.getArgumentArray(); - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - if (ft.getThrowable() != null && event.getThrowable() != null) { - throw new IllegalArgumentException("both last element in argument array and last argument are of type Throwable"); - } - - Throwable t = event.getThrowable(); - if (ft.getThrowable() != null) { - t = ft.getThrowable(); - throw new IllegalStateException("fix above code"); - } - - LogRecord record = new LogRecord(julLevel, ft.getMessage()); - record.setLoggerName(event.getLoggerName()); - record.setMillis(event.getTimeStamp()); - record.setSourceClassName(EventConstants.NA_SUBST); - record.setSourceMethodName(EventConstants.NA_SUBST); - - record.setThrown(t); - return record; - } } diff --git a/slf4j-log4j12/src/main/java/org/slf4j/log4j12/Log4jLoggerAdapter.java b/slf4j-log4j12/src/main/java/org/slf4j/log4j12/Log4jLoggerAdapter.java index 9fb1ba756..dbe726288 100755 --- a/slf4j-log4j12/src/main/java/org/slf4j/log4j12/Log4jLoggerAdapter.java +++ b/slf4j-log4j12/src/main/java/org/slf4j/log4j12/Log4jLoggerAdapter.java @@ -34,9 +34,11 @@ import org.slf4j.Logger; import org.slf4j.Marker; import org.slf4j.event.LoggingEvent; -import org.slf4j.helpers.FormattingTuple; -import org.slf4j.helpers.MarkerIgnoringBase; +import org.slf4j.helpers.LegacyAbstractLogger; import org.slf4j.helpers.MessageFormatter; +import org.slf4j.helpers.NormalizedParameters; +import org.slf4j.helpers.ParameterNormalizer; +import org.slf4j.helpers.SubstituteLogger; import org.slf4j.spi.LocationAwareLogger; /** @@ -57,7 +59,7 @@ * * @author Ceki Gülcü */ -public final class Log4jLoggerAdapter extends MarkerIgnoringBase implements LocationAwareLogger, Serializable { +public final class Log4jLoggerAdapter extends LegacyAbstractLogger implements LocationAwareLogger, Serializable { private static final long serialVersionUID = 6182834493563598289L; @@ -104,93 +106,6 @@ public boolean isTraceEnabled() { } } - /** - * Log a message object at level TRACE. - * - * @param msg - * - the message object to be logged - */ - public void trace(String msg) { - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msg, null); - } - - /** - * Log a message at level TRACE according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for level TRACE. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void trace(String format, Object arg) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level TRACE according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the TRACE level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void trace(String format, Object arg1, Object arg2) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level TRACE according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the TRACE level. - * - * - * @param format - * the format string - * @param arguments - * an array of arguments - */ - public void trace(String format, Object... arguments) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at level TRACE with an accompanying message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void trace(String msg, Throwable t) { - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msg, t); - } - /** * Is this logger instance enabled for the DEBUG level? * @@ -200,91 +115,6 @@ public boolean isDebugEnabled() { return logger.isDebugEnabled(); } - /** - * Log a message object at level DEBUG. - * - * @param msg - * - the message object to be logged - */ - public void debug(String msg) { - logger.log(FQCN, Level.DEBUG, msg, null); - } - - /** - * Log a message at level DEBUG according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for level DEBUG. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void debug(String format, Object arg) { - if (logger.isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level DEBUG according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the DEBUG level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void debug(String format, Object arg1, Object arg2) { - if (logger.isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level DEBUG according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the DEBUG level. - * - * - * @param format - * the format string - * @param arguments an array of arguments - */ - public void debug(String format, Object... arguments) { - if (logger.isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at level DEBUG with an accompanying message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void debug(String msg, Throwable t) { - logger.log(FQCN, Level.DEBUG, msg, t); - } /** * Is this logger instance enabled for the INFO level? @@ -295,93 +125,6 @@ public boolean isInfoEnabled() { return logger.isInfoEnabled(); } - /** - * Log a message object at the INFO level. - * - * @param msg - * - the message object to be logged - */ - public void info(String msg) { - logger.log(FQCN, Level.INFO, msg, null); - } - - /** - * Log a message at level INFO according to the specified format and argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void info(String format, Object arg) { - if (logger.isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the INFO level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void info(String format, Object arg1, Object arg2) { - if (logger.isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level INFO according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - * - * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - public void info(String format, Object... argArray) { - if (logger.isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the INFO level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void info(String msg, Throwable t) { - logger.log(FQCN, Level.INFO, msg, t); - } - /** * Is this logger instance enabled for the WARN level? * @@ -391,93 +134,6 @@ public boolean isWarnEnabled() { return logger.isEnabledFor(Level.WARN); } - /** - * Log a message object at the WARN level. - * - * @param msg - * - the message object to be logged - */ - public void warn(String msg) { - logger.log(FQCN, Level.WARN, msg, null); - } - - /** - * Log a message at the WARN level according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARN level. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void warn(String format, Object arg) { - if (logger.isEnabledFor(Level.WARN)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the WARN level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARN level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void warn(String format, Object arg1, Object arg2) { - if (logger.isEnabledFor(Level.WARN)) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level WARN according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARN level. - * - * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - public void warn(String format, Object... argArray) { - if (logger.isEnabledFor(Level.WARN)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the WARN level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void warn(String msg, Throwable t) { - logger.log(FQCN, Level.WARN, msg, t); - } /** * Is this logger instance enabled for level ERROR? @@ -488,102 +144,59 @@ public boolean isErrorEnabled() { return logger.isEnabledFor(Level.ERROR); } - /** - * Log a message object at the ERROR level. - * - * @param msg - * - the message object to be logged - */ - public void error(String msg) { - logger.log(FQCN, Level.ERROR, msg, null); - } - /** - * Log a message at the ERROR level according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the ERROR level. - * - * - * @param format - * the format string - * @param arg - * the argument - */ - public void error(String format, Object arg) { - if (logger.isEnabledFor(Level.ERROR)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable()); - } - } + @Override + public void log(Marker marker, String callerFQCN, int level, String msg, Object[] arguments, Throwable t) { + Level log4jLevel = toLog4jLevel(level); + NormalizedParameters np = ParameterNormalizer.normalize(msg, arguments, t); + String formattedMessage = MessageFormatter.basicArrayFormat(np.getMessage(), np.getArguments()); + logger.log(callerFQCN, log4jLevel, formattedMessage, np.getThrowable()); + } + + @Override + protected void handleNormalizedLoggingCall(org.slf4j.event.Level level, Marker marker, String msg, Object[] arguments, + Throwable throwable) { + Level log4jLevel = toLog4jLevel(level.toInt()); + String formattedMessage = MessageFormatter.basicArrayFormat(msg, arguments); + logger.log(getFullyQualifiedCallerName(), log4jLevel, formattedMessage, throwable); + } + + /** + * Called by {@link SubstituteLogger} + * @param event + */ + public void log(LoggingEvent event) { + Level log4jLevel = toLog4jLevel(event.getLevel().toInt()); + if (!logger.isEnabledFor(log4jLevel)) + return; - /** - * Log a message at the ERROR level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the ERROR level. - * - * - * @param format - * the format string - * @param arg1 - * the first argument - * @param arg2 - * the second argument - */ - public void error(String format, Object arg1, Object arg2) { - if (logger.isEnabledFor(Level.ERROR)) { - FormattingTuple ft = MessageFormatter.format(format, arg1, arg2); - logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable()); - } - } + org.apache.log4j.spi.LoggingEvent log4jevent = toLog4jEvent(event, log4jLevel); + logger.callAppenders(log4jevent); - /** - * Log a message at level ERROR according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the ERROR level. - * - * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - public void error(String format, Object... argArray) { - if (logger.isEnabledFor(Level.ERROR)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable()); - } } + + private org.apache.log4j.spi.LoggingEvent toLog4jEvent(LoggingEvent event, Level log4jLevel) { - /** - * Log an exception (throwable) at the ERROR level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - public void error(String msg, Throwable t) { - logger.log(FQCN, Level.ERROR, msg, t); - } + String formattedMessage = MessageFormatter.basicArrayFormat(event.getMessage(), event.getArgumentArray()); - public void log(Marker marker, String callerFQCN, int level, String msg, Object[] argArray, Throwable t) { - Level log4jLevel = toLog4jLevel(level); - logger.log(callerFQCN, log4jLevel, msg, t); + LocationInfo locationInfo = new LocationInfo(NA_SUBST, NA_SUBST, NA_SUBST, "0"); + + ThrowableInformation ti = null; + Throwable t = event.getThrowable(); + if (t != null) + ti = new ThrowableInformation(t); + + org.apache.log4j.spi.LoggingEvent log4jEvent = new org.apache.log4j.spi.LoggingEvent(FQCN, logger, event.getTimeStamp(), log4jLevel, formattedMessage, + event.getThreadName(), ti, null, locationInfo, null); + + return log4jEvent; } - private Level toLog4jLevel(int level) { + + + private Level toLog4jLevel(int slf4jLevelInt) { Level log4jLevel; - switch (level) { + switch (slf4jLevelInt) { case LocationAwareLogger.TRACE_INT: log4jLevel = traceCapable ? Level.TRACE : Level.DEBUG; break; @@ -600,36 +213,14 @@ private Level toLog4jLevel(int level) { log4jLevel = Level.ERROR; break; default: - throw new IllegalStateException("Level number " + level + " is not recognized."); + throw new IllegalStateException("Level number " + slf4jLevelInt + " is not recognized."); } return log4jLevel; } - public void log(LoggingEvent event) { - Level log4jLevel = toLog4jLevel(event.getLevel().toInt()); - if (!logger.isEnabledFor(log4jLevel)) - return; - - org.apache.log4j.spi.LoggingEvent log4jevent = toLog4jEvent(event, log4jLevel); - logger.callAppenders(log4jevent); - - } - - private org.apache.log4j.spi.LoggingEvent toLog4jEvent(LoggingEvent event, Level log4jLevel) { - - FormattingTuple ft = MessageFormatter.format(event.getMessage(), event.getArgumentArray(), event.getThrowable()); - - LocationInfo locationInfo = new LocationInfo(NA_SUBST, NA_SUBST, NA_SUBST, "0"); - - ThrowableInformation ti = null; - Throwable t = ft.getThrowable(); - if (t != null) - ti = new ThrowableInformation(t); - - org.apache.log4j.spi.LoggingEvent log4jEvent = new org.apache.log4j.spi.LoggingEvent(FQCN, logger, event.getTimeStamp(), log4jLevel, ft.getMessage(), - event.getThreadName(), ti, null, locationInfo, null); - - return log4jEvent; - } + @Override + protected String getFullyQualifiedCallerName() { + return FQCN; + } } diff --git a/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java b/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java index cce8c86a6..d2c49396f 100644 --- a/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java +++ b/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java @@ -28,10 +28,15 @@ import java.util.Date; import org.slf4j.Logger; +import org.slf4j.Marker; +import org.slf4j.event.Level; import org.slf4j.event.LoggingEvent; +import org.slf4j.helpers.AbstractLogger; import org.slf4j.helpers.FormattingTuple; import org.slf4j.helpers.MarkerIgnoringBase; import org.slf4j.helpers.MessageFormatter; +import org.slf4j.helpers.NormalizedParameters; +import org.slf4j.helpers.ParameterNormalizer; import org.slf4j.spi.LocationAwareLogger; /** @@ -49,11 +54,10 @@ *

  • org.slf4j.simpleLogger.cacheOutputStream - If the output * target is set to "System.out" or "System.err" (see preceding entry), by * default, logs will be output to the latest value referenced by - * System.out/err variables. By setting this - * parameter to true, the output stream will be cached, i.e. assigned once at - * initialization time and re-used independently of the current value referenced by - * System.out/err. - *
  • + * System.out/err variables. By setting this parameter to true, the + * output stream will be cached, i.e. assigned once at initialization time and + * re-used independently of the current value referenced by + * System.out/err. * *
  • org.slf4j.simpleLogger.defaultLogLevel - Default log level * for all instances of SimpleLogger. Must be one of ("trace", "debug", "info", @@ -140,467 +144,287 @@ * @author Robert Burrell Donkin * @author Cédrik LIME */ -public class SimpleLogger extends MarkerIgnoringBase { - - private static final long serialVersionUID = -632788891211436180L; - - private static long START_TIME = System.currentTimeMillis(); - - protected static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT; - protected static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT; - protected static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT; - protected static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT; - protected static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT; - // The OFF level can only be used in configuration files to disable logging. - // It has - // no printing method associated with it in o.s.Logger interface. - protected static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10; - - private static boolean INITIALIZED = false; - static SimpleLoggerConfiguration CONFIG_PARAMS = null; - - static void lazyInit() { - if (INITIALIZED) { - return; - } - INITIALIZED = true; - init(); - } - - // external software might be invoking this method directly. Do not rename - // or change its semantics. - static void init() { - CONFIG_PARAMS = new SimpleLoggerConfiguration(); - CONFIG_PARAMS.init(); - } - - /** The current log level */ - protected int currentLogLevel = LOG_LEVEL_INFO; - /** The short name of this simple log instance */ - private transient String shortLogName = null; - - /** - * All system properties used by SimpleLogger start with this - * prefix - */ - public static final String SYSTEM_PREFIX = "org.slf4j.simpleLogger."; - - public static final String LOG_KEY_PREFIX = SimpleLogger.SYSTEM_PREFIX + "log."; - - public static final String CACHE_OUTPUT_STREAM_STRING_KEY = SimpleLogger.SYSTEM_PREFIX + "cacheOutputStream"; - - public static final String WARN_LEVEL_STRING_KEY = SimpleLogger.SYSTEM_PREFIX + "warnLevelString"; - - public static final String LEVEL_IN_BRACKETS_KEY = SimpleLogger.SYSTEM_PREFIX + "levelInBrackets"; - - public static final String LOG_FILE_KEY = SimpleLogger.SYSTEM_PREFIX + "logFile"; - - public static final String SHOW_SHORT_LOG_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showShortLogName"; - - public static final String SHOW_LOG_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showLogName"; - - public static final String SHOW_THREAD_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showThreadName"; - - public static final String DATE_TIME_FORMAT_KEY = SimpleLogger.SYSTEM_PREFIX + "dateTimeFormat"; - - public static final String SHOW_DATE_TIME_KEY = SimpleLogger.SYSTEM_PREFIX + "showDateTime"; - - public static final String DEFAULT_LOG_LEVEL_KEY = SimpleLogger.SYSTEM_PREFIX + "defaultLogLevel"; - - /** - * Package access allows only {@link SimpleLoggerFactory} to instantiate - * SimpleLogger instances. - */ - SimpleLogger(String name) { - this.name = name; - - String levelString = recursivelyComputeLevelString(); - if (levelString != null) { - this.currentLogLevel = SimpleLoggerConfiguration.stringToLevel(levelString); - } else { - this.currentLogLevel = CONFIG_PARAMS.defaultLogLevel; - } - } - - String recursivelyComputeLevelString() { - String tempName = name; - String levelString = null; - int indexOfLastDot = tempName.length(); - while ((levelString == null) && (indexOfLastDot > -1)) { - tempName = tempName.substring(0, indexOfLastDot); - levelString = CONFIG_PARAMS.getStringProperty(SimpleLogger.LOG_KEY_PREFIX + tempName, null); - indexOfLastDot = String.valueOf(tempName).lastIndexOf("."); - } - return levelString; - } - - /** - * This is our internal implementation for logging regular - * (non-parameterized) log messages. - * - * @param level - * One of the LOG_LEVEL_XXX constants defining the log level - * @param message - * The message itself - * @param t - * The exception whose stack trace should be logged - */ - private void log(int level, String message, Throwable t) { - if (!isLevelEnabled(level)) { - return; - } - - StringBuilder buf = new StringBuilder(32); - - // Append date-time if so configured - if (CONFIG_PARAMS.showDateTime) { - if (CONFIG_PARAMS.dateFormatter != null) { - buf.append(getFormattedDate()); - buf.append(' '); - } else { - buf.append(System.currentTimeMillis() - START_TIME); - buf.append(' '); - } - } - - // Append current thread name if so configured - if (CONFIG_PARAMS.showThreadName) { - buf.append('['); - buf.append(Thread.currentThread().getName()); - buf.append("] "); - } - - if (CONFIG_PARAMS.levelInBrackets) - buf.append('['); - - // Append a readable representation of the log level - String levelStr = renderLevel(level); - buf.append(levelStr); - if (CONFIG_PARAMS.levelInBrackets) - buf.append(']'); - buf.append(' '); - - // Append the name of the log instance if so configured - if (CONFIG_PARAMS.showShortLogName) { - if (shortLogName == null) - shortLogName = computeShortName(); - buf.append(String.valueOf(shortLogName)).append(" - "); - } else if (CONFIG_PARAMS.showLogName) { - buf.append(String.valueOf(name)).append(" - "); - } - - // Append the message - buf.append(message); - - write(buf, t); - - } - - protected String renderLevel(int level) { - switch (level) { - case LOG_LEVEL_TRACE: - return "TRACE"; - case LOG_LEVEL_DEBUG: - return ("DEBUG"); - case LOG_LEVEL_INFO: - return "INFO"; - case LOG_LEVEL_WARN: - return CONFIG_PARAMS.warnLevelString; - case LOG_LEVEL_ERROR: - return "ERROR"; - } - throw new IllegalStateException("Unrecognized level [" + level + "]"); - } - - void write(StringBuilder buf, Throwable t) { - PrintStream targetStream = CONFIG_PARAMS.outputChoice.getTargetPrintStream(); - - targetStream.println(buf.toString()); - writeThrowable(t, targetStream); - targetStream.flush(); - } - - protected void writeThrowable(Throwable t, PrintStream targetStream) { - if (t != null) { - t.printStackTrace(targetStream); - } - } - - private String getFormattedDate() { - Date now = new Date(); - String dateText; - synchronized (CONFIG_PARAMS.dateFormatter) { - dateText = CONFIG_PARAMS.dateFormatter.format(now); - } - return dateText; - } - - private String computeShortName() { - return name.substring(name.lastIndexOf(".") + 1); - } - - /** - * For formatted messages, first substitute arguments and then log. - * - * @param level - * @param format - * @param arg1 - * @param arg2 - */ - private void formatAndLog(int level, String format, Object arg1, Object arg2) { - if (!isLevelEnabled(level)) { - return; - } - FormattingTuple tp = MessageFormatter.format(format, arg1, arg2); - log(level, tp.getMessage(), tp.getThrowable()); - } - - /** - * For formatted messages, first substitute arguments and then log. - * - * @param level - * @param format - * @param arguments - * a list of 3 ore more arguments - */ - private void formatAndLog(int level, String format, Object... arguments) { - if (!isLevelEnabled(level)) { - return; - } - FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments); - log(level, tp.getMessage(), tp.getThrowable()); - } - - /** - * Is the given log level currently enabled? - * - * @param logLevel is this level enabled? - * @return whether the logger is enabled for the given level - */ - protected boolean isLevelEnabled(int logLevel) { - // log level are numerically ordered so can use simple numeric - // comparison - return (logLevel >= currentLogLevel); - } - - /** Are {@code trace} messages currently enabled? */ - public boolean isTraceEnabled() { - return isLevelEnabled(LOG_LEVEL_TRACE); - } - - /** - * A simple implementation which logs messages of level TRACE according to - * the format outlined above. - */ - public void trace(String msg) { - log(LOG_LEVEL_TRACE, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * TRACE according to the format outlined above. - */ - public void trace(String format, Object param1) { - formatAndLog(LOG_LEVEL_TRACE, format, param1, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * TRACE according to the format outlined above. - */ - public void trace(String format, Object param1, Object param2) { - formatAndLog(LOG_LEVEL_TRACE, format, param1, param2); - } - - /** - * Perform double parameter substitution before logging the message of level - * TRACE according to the format outlined above. - */ - public void trace(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_TRACE, format, argArray); - } - - /** Log a message of level TRACE, including an exception. */ - public void trace(String msg, Throwable t) { - log(LOG_LEVEL_TRACE, msg, t); - } - - /** Are {@code debug} messages currently enabled? */ - public boolean isDebugEnabled() { - return isLevelEnabled(LOG_LEVEL_DEBUG); - } - - /** - * A simple implementation which logs messages of level DEBUG according to - * the format outlined above. - */ - public void debug(String msg) { - log(LOG_LEVEL_DEBUG, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * DEBUG according to the format outlined above. - */ - public void debug(String format, Object param1) { - formatAndLog(LOG_LEVEL_DEBUG, format, param1, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * DEBUG according to the format outlined above. - */ - public void debug(String format, Object param1, Object param2) { - formatAndLog(LOG_LEVEL_DEBUG, format, param1, param2); - } - - /** - * Perform double parameter substitution before logging the message of level - * DEBUG according to the format outlined above. - */ - public void debug(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_DEBUG, format, argArray); - } - - /** Log a message of level DEBUG, including an exception. */ - public void debug(String msg, Throwable t) { - log(LOG_LEVEL_DEBUG, msg, t); - } - - /** Are {@code info} messages currently enabled? */ - public boolean isInfoEnabled() { - return isLevelEnabled(LOG_LEVEL_INFO); - } - - /** - * A simple implementation which logs messages of level INFO according to - * the format outlined above. - */ - public void info(String msg) { - log(LOG_LEVEL_INFO, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * INFO according to the format outlined above. - */ - public void info(String format, Object arg) { - formatAndLog(LOG_LEVEL_INFO, format, arg, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * INFO according to the format outlined above. - */ - public void info(String format, Object arg1, Object arg2) { - formatAndLog(LOG_LEVEL_INFO, format, arg1, arg2); - } - - /** - * Perform double parameter substitution before logging the message of level - * INFO according to the format outlined above. - */ - public void info(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_INFO, format, argArray); - } - - /** Log a message of level INFO, including an exception. */ - public void info(String msg, Throwable t) { - log(LOG_LEVEL_INFO, msg, t); - } - - /** Are {@code warn} messages currently enabled? */ - public boolean isWarnEnabled() { - return isLevelEnabled(LOG_LEVEL_WARN); - } - - /** - * A simple implementation which always logs messages of level WARN - * according to the format outlined above. - */ - public void warn(String msg) { - log(LOG_LEVEL_WARN, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * WARN according to the format outlined above. - */ - public void warn(String format, Object arg) { - formatAndLog(LOG_LEVEL_WARN, format, arg, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * WARN according to the format outlined above. - */ - public void warn(String format, Object arg1, Object arg2) { - formatAndLog(LOG_LEVEL_WARN, format, arg1, arg2); - } - - /** - * Perform double parameter substitution before logging the message of level - * WARN according to the format outlined above. - */ - public void warn(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_WARN, format, argArray); - } - - /** Log a message of level WARN, including an exception. */ - public void warn(String msg, Throwable t) { - log(LOG_LEVEL_WARN, msg, t); - } - - /** Are {@code error} messages currently enabled? */ - public boolean isErrorEnabled() { - return isLevelEnabled(LOG_LEVEL_ERROR); - } - - /** - * A simple implementation which always logs messages of level ERROR - * according to the format outlined above. - */ - public void error(String msg) { - log(LOG_LEVEL_ERROR, msg, null); - } - - /** - * Perform single parameter substitution before logging the message of level - * ERROR according to the format outlined above. - */ - public void error(String format, Object arg) { - formatAndLog(LOG_LEVEL_ERROR, format, arg, null); - } - - /** - * Perform double parameter substitution before logging the message of level - * ERROR according to the format outlined above. - */ - public void error(String format, Object arg1, Object arg2) { - formatAndLog(LOG_LEVEL_ERROR, format, arg1, arg2); - } - - /** - * Perform double parameter substitution before logging the message of level - * ERROR according to the format outlined above. - */ - public void error(String format, Object... argArray) { - formatAndLog(LOG_LEVEL_ERROR, format, argArray); - } - - /** Log a message of level ERROR, including an exception. */ - public void error(String msg, Throwable t) { - log(LOG_LEVEL_ERROR, msg, t); - } - - public void log(LoggingEvent event) { - int levelInt = event.getLevel().toInt(); - - if (!isLevelEnabled(levelInt)) { - return; - } - FormattingTuple tp = MessageFormatter.arrayFormat(event.getMessage(), event.getArgumentArray(), event.getThrowable()); - log(levelInt, tp.getMessage(), event.getThrowable()); - } +public class SimpleLogger extends AbstractLogger { + + private static final long serialVersionUID = -632788891211436180L; + + private static long START_TIME = System.currentTimeMillis(); + + protected static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT; + protected static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT; + protected static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT; + protected static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT; + protected static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT; + + static char SP = ' '; + + // The OFF level can only be used in configuration files to disable logging. + // It has + // no printing method associated with it in o.s.Logger interface. + protected static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10; + + private static boolean INITIALIZED = false; + static SimpleLoggerConfiguration CONFIG_PARAMS = null; + + static void lazyInit() { + if (INITIALIZED) { + return; + } + INITIALIZED = true; + init(); + } + + // external software might be invoking this method directly. Do not rename + // or change its semantics. + static void init() { + CONFIG_PARAMS = new SimpleLoggerConfiguration(); + CONFIG_PARAMS.init(); + } + + /** The current log level */ + protected int currentLogLevel = LOG_LEVEL_INFO; + /** The short name of this simple log instance */ + private transient String shortLogName = null; + + /** + * All system properties used by SimpleLogger start with this + * prefix + */ + public static final String SYSTEM_PREFIX = "org.slf4j.simpleLogger."; + + public static final String LOG_KEY_PREFIX = SimpleLogger.SYSTEM_PREFIX + "log."; + + public static final String CACHE_OUTPUT_STREAM_STRING_KEY = SimpleLogger.SYSTEM_PREFIX + "cacheOutputStream"; + + public static final String WARN_LEVEL_STRING_KEY = SimpleLogger.SYSTEM_PREFIX + "warnLevelString"; + + public static final String LEVEL_IN_BRACKETS_KEY = SimpleLogger.SYSTEM_PREFIX + "levelInBrackets"; + + public static final String LOG_FILE_KEY = SimpleLogger.SYSTEM_PREFIX + "logFile"; + + public static final String SHOW_SHORT_LOG_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showShortLogName"; + + public static final String SHOW_LOG_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showLogName"; + + public static final String SHOW_THREAD_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showThreadName"; + + public static final String DATE_TIME_FORMAT_KEY = SimpleLogger.SYSTEM_PREFIX + "dateTimeFormat"; + + public static final String SHOW_DATE_TIME_KEY = SimpleLogger.SYSTEM_PREFIX + "showDateTime"; + + public static final String DEFAULT_LOG_LEVEL_KEY = SimpleLogger.SYSTEM_PREFIX + "defaultLogLevel"; + + /** + * Package access allows only {@link SimpleLoggerFactory} to instantiate + * SimpleLogger instances. + */ + SimpleLogger(String name) { + this.name = name; + + String levelString = recursivelyComputeLevelString(); + if (levelString != null) { + this.currentLogLevel = SimpleLoggerConfiguration.stringToLevel(levelString); + } else { + this.currentLogLevel = CONFIG_PARAMS.defaultLogLevel; + } + } + + String recursivelyComputeLevelString() { + String tempName = name; + String levelString = null; + int indexOfLastDot = tempName.length(); + while ((levelString == null) && (indexOfLastDot > -1)) { + tempName = tempName.substring(0, indexOfLastDot); + levelString = CONFIG_PARAMS.getStringProperty(SimpleLogger.LOG_KEY_PREFIX + tempName, null); + indexOfLastDot = String.valueOf(tempName).lastIndexOf("."); + } + return levelString; + } + + + + + void write(StringBuilder buf, Throwable t) { + PrintStream targetStream = CONFIG_PARAMS.outputChoice.getTargetPrintStream(); + + targetStream.println(buf.toString()); + writeThrowable(t, targetStream); + targetStream.flush(); + } + + protected void writeThrowable(Throwable t, PrintStream targetStream) { + if (t != null) { + t.printStackTrace(targetStream); + } + } + + private String getFormattedDate() { + Date now = new Date(); + String dateText; + synchronized (CONFIG_PARAMS.dateFormatter) { + dateText = CONFIG_PARAMS.dateFormatter.format(now); + } + return dateText; + } + + private String computeShortName() { + return name.substring(name.lastIndexOf(".") + 1); + } + +// /** +// * For formatted messages, first substitute arguments and then log. +// * +// * @param level +// * @param format +// * @param arg1 +// * @param arg2 +// */ +// private void formatAndLog(int level, String format, Object arg1, Object arg2) { +// if (!isLevelEnabled(level)) { +// return; +// } +// FormattingTuple tp = MessageFormatter.format(format, arg1, arg2); +// log(level, tp.getMessage(), tp.getThrowable()); +// } + +// /** +// * For formatted messages, first substitute arguments and then log. +// * +// * @param level +// * @param format +// * @param arguments +// * a list of 3 ore more arguments +// */ +// private void formatAndLog(int level, String format, Object... arguments) { +// if (!isLevelEnabled(level)) { +// return; +// } +// FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments); +// log(level, tp.getMessage(), tp.getThrowable()); +// } + + /** + * Is the given log level currently enabled? + * + * @param logLevel is this level enabled? + * @return whether the logger is enabled for the given level + */ + protected boolean isLevelEnabled(int logLevel) { + // log level are numerically ordered so can use simple numeric + // comparison + return (logLevel >= currentLogLevel); + } + + /** Are {@code trace} messages currently enabled? */ + public boolean isTraceEnabled() { + return isLevelEnabled(LOG_LEVEL_TRACE); + } + + /** Are {@code debug} messages currently enabled? */ + public boolean isDebugEnabled() { + return isLevelEnabled(LOG_LEVEL_DEBUG); + } + + /** Are {@code info} messages currently enabled? */ + public boolean isInfoEnabled() { + return isLevelEnabled(LOG_LEVEL_INFO); + } + + /** Are {@code warn} messages currently enabled? */ + public boolean isWarnEnabled() { + return isLevelEnabled(LOG_LEVEL_WARN); + } + + /** Are {@code error} messages currently enabled? */ + public boolean isErrorEnabled() { + return isLevelEnabled(LOG_LEVEL_ERROR); + } + + /** + * This is our internal implementation for logging regular (non-parameterized) + * log messages. + * + * @param level One of the LOG_LEVEL_XXX constants defining the log level + * @param message The message itself + * @param t The exception whose stack trace should be logged + */ + @Override + protected void handleNormalizedLoggingCall(Level level, Marker marker, String messagePattern, Object[] arguments, + Throwable t) { + + first convert to an event and then log + + StringBuilder buf = new StringBuilder(32); + + // Append date-time if so configured + if (CONFIG_PARAMS.showDateTime) { + if (CONFIG_PARAMS.dateFormatter != null) { + buf.append(getFormattedDate()); + buf.append(' '); + } else { + buf.append(System.currentTimeMillis() - START_TIME); + buf.append(' '); + } + } + + // Append current thread name if so configured + if (CONFIG_PARAMS.showThreadName) { + buf.append('['); + buf.append(Thread.currentThread().getName()); + buf.append("] "); + } + + if (CONFIG_PARAMS.levelInBrackets) + buf.append('['); + + // Append a readable representation of the log level + String levelStr = level.name(); + buf.append(levelStr); + if (CONFIG_PARAMS.levelInBrackets) + buf.append(']'); + buf.append(' '); + + // Append the name of the log instance if so configured + if (CONFIG_PARAMS.showShortLogName) { + if (shortLogName == null) + shortLogName = computeShortName(); + buf.append(String.valueOf(shortLogName)).append(" - "); + } else if (CONFIG_PARAMS.showLogName) { + buf.append(String.valueOf(name)).append(" - "); + } + + buf.append(SP).append(marker.getName()).append(SP); + + String formattedMessage = MessageFormatter.basicArrayFormat(messagePattern, arguments); + + // Append the message + buf.append(formattedMessage); + + write(buf, t); + } + + + public void log(LoggingEvent event) { + int levelInt = event.getLevel().toInt(); + + if (!isLevelEnabled(levelInt)) { + return; + } + + NormalizedParameters np = ParameterNormalizer.normalize(event); + + + + FormattingTuple tp = MessageFormatter.arrayFormat(event.getMessage(), event.getArgumentArray(), + event.getThrowable()); + + handleNormalizedLoggingCall(level, event.getMarkers(), messagePattern, arguments, t); + log(event.getLevel(), tp.getMessage(), event.getThrowable()); + } + + @Override + protected String getFullyQualifiedCallerName() { + return null; + } }