From 37ffaa935a8b8c76fa3c943e9da337fc24f4cb36 Mon Sep 17 00:00:00 2001 From: John Vasileff Date: Fri, 16 Sep 2011 12:48:08 -0400 Subject: [PATCH] add throwable to Message objects, remove from log methods --- .../src/main/java/org/apache/log4j/Category.java | 22 +- .../main/java/org/apache/logging/log4j/Logger.java | 102 ------- .../org/apache/logging/log4j/message/Message.java | 7 + .../logging/log4j/message/ObjectMessage.java | 29 ++- .../logging/log4j/message/SimpleMessage.java | 29 ++- .../log4j/message/StructuredDataMessage.java | 7 + .../apache/logging/log4j/spi/AbstractLogger.java | 316 +++++-------------- .../logging/log4j/spi/AbstractLoggerWrapper.java | 9 +- .../apache/logging/log4j/status/StatusData.java | 17 +- .../apache/logging/log4j/status/StatusLogger.java | 6 +- .../org/apache/logging/log4j/SimpleLogger.java | 8 +- .../apache/logging/log4j/core/AbstractServer.java | 3 +- .../java/org/apache/logging/log4j/core/Filter.java | 2 +- .../apache/logging/log4j/core/Log4jLogEvent.java | 16 +- .../org/apache/logging/log4j/core/LogEvent.java | 7 - .../apache/logging/log4j/core/LogEventFactory.java | 2 +- .../java/org/apache/logging/log4j/core/Logger.java | 12 +- .../log4j/core/appender/flume/FlumeEvent.java | 4 - .../logging/log4j/core/config/LoggerConfig.java | 9 +- .../log4j/core/filter/DynamicThresholdFilter.java | 3 +- .../logging/log4j/core/filter/FilterBase.java | 2 +- .../logging/log4j/core/filter/MarkerFilter.java | 3 +- .../logging/log4j/core/filter/RegexFilter.java | 3 +- .../log4j/core/filter/StructuredDataFilter.java | 2 +- .../log4j/core/filter/ThreadContextMapFilter.java | 2 +- .../logging/log4j/core/filter/ThresholdFilter.java | 3 +- .../logging/log4j/core/layout/HTMLLayout.java | 2 +- .../logging/log4j/core/layout/XMLLayout.java | 2 +- .../core/pattern/ThrowablePatternConverter.java | 2 +- .../log4j/core/appender/FileAppenderTest.java | 2 +- .../core/appender/OutputStreamAppenderTest.java | 2 +- .../core/filter/DynamicThresholdFilterTest.java | 4 +- .../log4j/core/filter/MarkerFilterTest.java | 4 +- .../logging/log4j/core/filter/RegexFilterTest.java | 4 +- .../core/filter/StructuredDataFilterTest.java | 8 +- .../log4j/core/filter/ThresholdFilterTest.java | 4 +- .../logging/log4j/core/filter/TimeFilterTest.java | 6 +- .../src/main/java/org/slf4j/impl/SLF4JLogger.java | 82 +++--- 38 files changed, 269 insertions(+), 478 deletions(-) diff --git a/log4j12-api/src/main/java/org/apache/log4j/Category.java b/log4j12-api/src/main/java/org/apache/log4j/Category.java index 8949e64..8ab459a 100644 --- a/log4j12-api/src/main/java/org/apache/log4j/Category.java +++ b/log4j12-api/src/main/java/org/apache/log4j/Category.java @@ -253,8 +253,12 @@ public class Category { } public void forcedLog(String fqcn, Priority level, Object message, Throwable t) { + forcedLog(fqcn, level, new ObjectMessage(message, t)); + } + + private void forcedLog(String fqcn, Priority level, Message msg) { org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString()); - ((CategoryFactory.CategoryLogger) logger).log(null, fqcn, lvl, new ObjectMessage(message), t); + ((CategoryFactory.CategoryLogger) logger).log(null, fqcn, lvl, msg); } public boolean exists(String name) { @@ -293,15 +297,17 @@ public class Category { public void l7dlog(Priority priority, String key, Throwable t) { if (isEnabledFor(priority)) { - Message msg = new LocalizedMessage(bundle, key, null); - forcedLog(FQCN, priority, msg, t); + LocalizedMessage msg = new LocalizedMessage(bundle, key, null); + msg.setThrowable(t); + forcedLog(FQCN, priority, msg); } } public void l7dlog(Priority priority, String key, Object[] params, Throwable t) { if (isEnabledFor(priority)) { - Message msg = new LocalizedMessage(bundle, key, params); - forcedLog(FQCN, priority, msg, t); + LocalizedMessage msg = new LocalizedMessage(bundle, key, params); + msg.setThrowable(t); + forcedLog(FQCN, priority, msg); } } @@ -359,12 +365,12 @@ public class Category { @Override public void log(Marker marker, String fqcn, org.apache.logging.log4j.Level level, - Message data, Throwable t) { - super.log(marker, fqcn, level, data, t); + Message data) { + super.log(marker, fqcn, level, data); } public boolean isEnabledFor(org.apache.logging.log4j.Level level) { - return isEnabled(level, null, null); + return isEnabled(level, null, (Object) null, null); } } } diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/Logger.java b/log4j2-api/src/main/java/org/apache/logging/log4j/Logger.java index 2ef7778..28a3290 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/Logger.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/Logger.java @@ -206,29 +206,12 @@ public interface Logger { /** * Log a message with the specific Marker at the TRACE level. * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void trace(Message msg, Throwable t); - - /** - * Log a message with the specific Marker at the TRACE level. - * * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ void trace(Marker marker, Message msg); /** - * Log a message with the specific Marker at the TRACE level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void trace(Marker marker, Message msg, Throwable t); - - /** * Log a message object with the {@link org.apache.logging.log4j.Level#DEBUG DEBUG} level. * * @param message the message object to log. @@ -339,29 +322,12 @@ public interface Logger { /** * Log a message with the specific Marker at the DEBUG level. * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void debug(Message msg, Throwable t); - - /** - * Log a message with the specific Marker at the DEBUG level. - * * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ void debug(Marker marker, Message msg); /** - * Log a message with the specific Marker at the DEBUG level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void debug(Marker marker, Message msg, Throwable t); - - /** * Log a message object with the {@link org.apache.logging.log4j.Level#INFO INFO} level. * * @param message the message object to log. @@ -482,29 +448,12 @@ public interface Logger { /** * Log a message with the specific Marker at the INFO level. * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void info(Message msg, Throwable t); - - /** - * Log a message with the specific Marker at the INFO level. - * * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ void info(Marker marker, Message msg); /** - * Log a message with the specific Marker at the INFO level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void info(Marker marker, Message msg, Throwable t); - - /** * Log a message object with the {@link org.apache.logging.log4j.Level#WARN WARN} level. * * @param message the message object to log. @@ -624,29 +573,12 @@ public interface Logger { /** * Log a message with the specific Marker at the WARN level. * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void warn(Message msg, Throwable t); - - /** - * Log a message with the specific Marker at the WARN level. - * * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ void warn(Marker marker, Message msg); /** - * Log a message with the specific Marker at the WARN level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void warn(Marker marker, Message msg, Throwable t); - - /** * Log a message object with the {@link org.apache.logging.log4j.Level#ERROR ERROR} level. * * @param message the message object to log. @@ -767,29 +699,12 @@ public interface Logger { /** * Log a message with the specific Marker at the ERROR level. * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void error(Message msg, Throwable t); - - /** - * Log a message with the specific Marker at the ERROR level. - * * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ void error(Marker marker, Message msg); /** - * Log a message with the specific Marker at the ERROR level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void error(Marker marker, Message msg, Throwable t); - - /** * Log a message object with the {@link org.apache.logging.log4j.Level#FATAL FATAL} level. * * @param message the message object to log. @@ -913,25 +828,8 @@ public interface Logger { /** * Log a message with the specific Marker at the FATAL level. * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void fatal(Message msg, Throwable t); - - /** - * Log a message with the specific Marker at the FATAL level. - * * @param marker the marker data specific to this log statement * @param msg the message string to be logged */ void fatal(Marker marker, Message msg); - - /** - * Log a message with the specific Marker at the FATAL level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - void fatal(Marker marker, Message msg, Throwable t); } diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java b/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java index ad66933..448dc37 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java @@ -60,4 +60,11 @@ public interface Message extends Serializable { * @return An array of parameter values or null. */ Object[] getParameters(); + + /** + * Returns the Throwable associated with this Message, or null. + * + * @return the throwable associated with this Message, or null. + */ + Throwable getThrowable(); } diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java b/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java index 6a374d0..71433a2 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java @@ -28,6 +28,7 @@ public class ObjectMessage implements Message, Serializable { private static final long serialVersionUID = -5903272448334166185L; private transient Object obj; + private transient Throwable throwable; /** * Create the ObjectMessage. @@ -38,6 +39,16 @@ public class ObjectMessage implements Message, Serializable { } /** + * Create the ObjectMessage. + * @param obj The Object to format. + * @param throwable The Throwable. + */ + public ObjectMessage(Object obj, Throwable throwable) { + this(obj); + this.throwable = throwable; + } + + /** * Return the formatted object message. * @return the formatted object message. */ @@ -61,6 +72,10 @@ public class ObjectMessage implements Message, Serializable { return new Object[]{obj}; } + public Throwable getThrowable() { + return throwable; + } + public boolean equals(Object o) { if (this == o) { return true; @@ -71,15 +86,25 @@ public class ObjectMessage implements Message, Serializable { ObjectMessage that = (ObjectMessage) o; + if (throwable != null ? !throwable.equals(that.throwable) : that.throwable != null) { + return false; + } + return !(obj != null ? !obj.equals(that.obj) : that.obj != null); } public int hashCode() { - return obj != null ? obj.hashCode() : 0; + if (obj != null) { + return obj.hashCode(); + } else if (throwable != null) { + return throwable.hashCode(); + } else { + return 0; + } } public String toString() { - return "ObjectMessage[obj=" + obj.toString() + "]"; + return "ObjectMessage[obj=" + obj.toString() + ", throwable=" + throwable + "]"; } private void writeObject(ObjectOutputStream out) throws IOException { diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java b/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java index a38b0d7..a3d87b7 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java @@ -25,6 +25,7 @@ public class SimpleMessage implements Message, Serializable { private static final long serialVersionUID = -8398002534962715992L; private final String message; + private transient Throwable throwable; /** * Basic constructor. @@ -42,6 +43,16 @@ public class SimpleMessage implements Message, Serializable { } /** + * Constructor that includes the message and throwable. + * @param message The String message. + * @param throwable The Throwable. + */ + public SimpleMessage(String message, Throwable throwable) { + this(message); + this.throwable = throwable; + } + + /** * Return the message. * @return the message. */ @@ -65,6 +76,10 @@ public class SimpleMessage implements Message, Serializable { return null; } + public Throwable getThrowable() { + return throwable; + } + public boolean equals(Object o) { if (this == o) { return true; @@ -75,14 +90,24 @@ public class SimpleMessage implements Message, Serializable { SimpleMessage that = (SimpleMessage) o; + if (throwable != null ? !throwable.equals(that.throwable) : that.throwable != null) { + return false; + } + return !(message != null ? !message.equals(that.message) : that.message != null); } public int hashCode() { - return message != null ? message.hashCode() : 0; + if (message != null) { + return message.hashCode(); + } else if (throwable != null) { + return throwable.hashCode(); + } else { + return 0; + } } public String toString() { - return "SimpleMessage[message=" + message + "]"; + return "SimpleMessage[message=" + message + ", throwable=" + throwable + "]"; } } diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java b/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java index c3a1385..67711b3 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java @@ -161,6 +161,13 @@ public class StructuredDataMessage implements FormattedMessage, Serializable { } /** + * @return null; StrucutredDataMessages never have Throwables. + */ + public Throwable getThrowable() { + return null; + } + + /** * Clear the data. */ public void clear() { diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java b/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java index 86d22e4..75c6a69 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java @@ -67,7 +67,7 @@ public abstract class AbstractLogger implements Logger { */ public void entry() { if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) { - log(ENTRY_MARKER, getFQCN(), Level.TRACE, new SimpleMessage(" entry"), null); + log(ENTRY_MARKER, getFQCN(), Level.TRACE, new SimpleMessage(" entry")); } } @@ -79,7 +79,7 @@ public abstract class AbstractLogger implements Logger { */ public void entry(Object... params) { if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) { - log(ENTRY_MARKER, getFQCN(), Level.TRACE, entryMsg(params.length, params), null); + log(ENTRY_MARKER, getFQCN(), Level.TRACE, entryMsg(params.length, params)); } } @@ -88,7 +88,7 @@ public abstract class AbstractLogger implements Logger { */ public void exit() { if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) { - log(EXIT_MARKER, getFQCN(), Level.TRACE, exitMsg(null), null); + log(EXIT_MARKER, getFQCN(), Level.TRACE, exitMsg(null)); } } @@ -99,7 +99,7 @@ public abstract class AbstractLogger implements Logger { */ public void exit(Object result) { if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) { - log(EXIT_MARKER, getFQCN(), Level.TRACE, exitMsg(result), null); + log(EXIT_MARKER, getFQCN(), Level.TRACE, exitMsg(result)); } } @@ -110,7 +110,7 @@ public abstract class AbstractLogger implements Logger { */ public void throwing(Throwable t) { if (isEnabled(Level.ERROR, THROWING_MARKER, (Object) null, null)) { - log(THROWING_MARKER, getFQCN(), Level.ERROR, new SimpleMessage("throwing"), t); + log(THROWING_MARKER, getFQCN(), Level.ERROR, new SimpleMessage("throwing", t)); } } @@ -123,7 +123,7 @@ public abstract class AbstractLogger implements Logger { */ public void throwing(Level level, Throwable t) { if (isEnabled(level, THROWING_MARKER, (Object) null, null)) { - log(THROWING_MARKER, getFQCN(), level, new SimpleMessage("throwing"), t); + log(THROWING_MARKER, getFQCN(), level, new SimpleMessage("throwing", t)); } } @@ -134,7 +134,7 @@ public abstract class AbstractLogger implements Logger { */ public void catching(Throwable t) { if (isEnabled(Level.DEBUG, THROWING_MARKER, (Object) null, null)) { - log(THROWING_MARKER, getFQCN(), Level.DEBUG, new SimpleMessage("catching"), t); + log(THROWING_MARKER, getFQCN(), Level.DEBUG, new SimpleMessage("catching", t)); } } @@ -146,7 +146,7 @@ public abstract class AbstractLogger implements Logger { */ public void catching(Level level, Throwable t) { if (isEnabled(level, THROWING_MARKER, (Object) null, null)) { - log(THROWING_MARKER, getFQCN(), level, new SimpleMessage("catching"), t); + log(THROWING_MARKER, getFQCN(), level, new SimpleMessage("catching", t)); } } @@ -157,7 +157,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(String message) { if (isEnabled(Level.TRACE, null, message)) { - log(null, getFQCN(), Level.TRACE, new SimpleMessage(message), null); + log(null, getFQCN(), Level.TRACE, new SimpleMessage(message)); } } @@ -169,7 +169,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Marker marker, String message) { if (isEnabled(Level.TRACE, marker, message)) { - log(marker, getFQCN(), Level.TRACE, new SimpleMessage(message), null); + log(marker, getFQCN(), Level.TRACE, new SimpleMessage(message)); } } @@ -186,7 +186,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(String message, Throwable t) { if (isEnabled(Level.TRACE, null, message, t)) { - log(null, getFQCN(), Level.TRACE, new SimpleMessage(message), t); + log(null, getFQCN(), Level.TRACE, new SimpleMessage(message, t)); } } @@ -205,7 +205,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Marker marker, String message, Throwable t) { if (isEnabled(Level.TRACE, marker, message, t)) { - log(marker, getFQCN(), Level.TRACE, new SimpleMessage(message), t); + log(marker, getFQCN(), Level.TRACE, new SimpleMessage(message, t)); } } @@ -216,7 +216,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Object message) { if (isEnabled(Level.TRACE, null, message, null)) { - log(null, getFQCN(), Level.TRACE, new ObjectMessage(message), null); + log(null, getFQCN(), Level.TRACE, new ObjectMessage(message)); } } @@ -228,7 +228,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Marker marker, Object message) { if (isEnabled(Level.TRACE, marker, message, null)) { - log(marker, getFQCN(), Level.TRACE, new ObjectMessage(message), null); + log(marker, getFQCN(), Level.TRACE, new ObjectMessage(message)); } } @@ -245,7 +245,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Object message, Throwable t) { if (isEnabled(Level.TRACE, null, message, t)) { - log(null, getFQCN(), Level.TRACE, new ObjectMessage(message), t); + log(null, getFQCN(), Level.TRACE, new ObjectMessage(message, t)); } } @@ -263,7 +263,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Marker marker, Object message, Throwable t) { if (isEnabled(Level.TRACE, marker, message, t)) { - log(marker, getFQCN(), Level.TRACE, new ObjectMessage(message), t); + log(marker, getFQCN(), Level.TRACE, new ObjectMessage(message, t)); } } @@ -275,7 +275,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(String message, Object... params) { if (isEnabled(Level.TRACE, null, message, params)) { - log(null, getFQCN(), Level.TRACE, new ParameterizedMessage(message, params), null); + log(null, getFQCN(), Level.TRACE, new ParameterizedMessage(message, params)); } } @@ -288,7 +288,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Marker marker, String message, Object... params) { if (isEnabled(Level.TRACE, marker, message, params)) { - log(marker, getFQCN(), Level.TRACE, new ParameterizedMessage(message, params), null); + log(marker, getFQCN(), Level.TRACE, new ParameterizedMessage(message, params)); } } @@ -320,19 +320,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Message msg) { if (isEnabled(Level.TRACE, null, msg, null)) { - log(null, getFQCN(), Level.TRACE, msg, null); - } - } - - /** - * Log a message with the specific Marker at the TRACE level. - * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void trace(Message msg, Throwable t) { - if (isEnabled(Level.TRACE, null, msg, t)) { - log(null, getFQCN(), Level.TRACE, msg, t); + log(null, getFQCN(), Level.TRACE, msg); } } @@ -344,20 +332,7 @@ public abstract class AbstractLogger implements Logger { */ public void trace(Marker marker, Message msg) { if (isEnabled(Level.TRACE, marker, msg, null)) { - log(marker, getFQCN(), Level.TRACE, msg, null); - } - } - - /** - * Log a message with the specific Marker at the TRACE level. - * - * @param marker the marker data specific to this log statement. - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void trace(Marker marker, Message msg, Throwable t) { - if (isEnabled(Level.TRACE, marker, msg, t)) { - log(marker, getFQCN(), Level.TRACE, msg, t); + log(marker, getFQCN(), Level.TRACE, msg); } } @@ -368,7 +343,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(String message) { if (isEnabled(Level.DEBUG, null, message)) { - log(null, getFQCN(), Level.DEBUG, new SimpleMessage(message), null); + log(null, getFQCN(), Level.DEBUG, new SimpleMessage(message)); } } @@ -380,7 +355,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Marker marker, String message) { if (isEnabled(Level.DEBUG, marker, message)) { - log(marker, getFQCN(), Level.DEBUG, new SimpleMessage(message), null); + log(marker, getFQCN(), Level.DEBUG, new SimpleMessage(message)); } } @@ -393,7 +368,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(String message, Throwable t) { if (isEnabled(Level.DEBUG, null, message, t)) { - log(null, getFQCN(), Level.DEBUG, new SimpleMessage(message), t); + log(null, getFQCN(), Level.DEBUG, new SimpleMessage(message, t)); } } @@ -407,7 +382,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Marker marker, String message, Throwable t) { if (isEnabled(Level.DEBUG, marker, message, t)) { - log(marker, getFQCN(), Level.DEBUG, new SimpleMessage(message), t); + log(marker, getFQCN(), Level.DEBUG, new SimpleMessage(message, t)); } } /** @@ -417,7 +392,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Object message) { if (isEnabled(Level.DEBUG, null, message, null)) { - log(null, getFQCN(), Level.DEBUG, new ObjectMessage(message), null); + log(null, getFQCN(), Level.DEBUG, new ObjectMessage(message)); } } @@ -429,7 +404,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Marker marker, Object message) { if (isEnabled(Level.DEBUG, marker, message, null)) { - log(marker, getFQCN(), Level.DEBUG, new ObjectMessage(message), null); + log(marker, getFQCN(), Level.DEBUG, new ObjectMessage(message)); } } @@ -442,7 +417,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Object message, Throwable t) { if (isEnabled(Level.DEBUG, null, message, t)) { - log(null, getFQCN(), Level.DEBUG, new ObjectMessage(message), t); + log(null, getFQCN(), Level.DEBUG, new ObjectMessage(message, t)); } } @@ -456,7 +431,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Marker marker, Object message, Throwable t) { if (isEnabled(Level.DEBUG, marker, message, t)) { - log(marker, getFQCN(), Level.DEBUG, new ObjectMessage(message), t); + log(marker, getFQCN(), Level.DEBUG, new ObjectMessage(message, t)); } } @@ -468,7 +443,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(String message, Object... params) { if (isEnabled(Level.DEBUG, null, message, params)) { - log(null, getFQCN(), Level.DEBUG, new ParameterizedMessage(message, params), null); + log(null, getFQCN(), Level.DEBUG, new ParameterizedMessage(message, params)); } } @@ -481,7 +456,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Marker marker, String message, Object... params) { if (isEnabled(Level.DEBUG, marker, message, params)) { - log(marker, getFQCN(), Level.DEBUG, new ParameterizedMessage(message, params), null); + log(marker, getFQCN(), Level.DEBUG, new ParameterizedMessage(message, params)); } } @@ -492,7 +467,7 @@ public abstract class AbstractLogger implements Logger { * DEBUG, false otherwise. */ public boolean isDebugEnabled() { - return isEnabled(Level.DEBUG, null, null); + return isEnabled(Level.DEBUG, null, (Object) null, null); } /** @@ -513,19 +488,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Message msg) { if (isEnabled(Level.TRACE, null, msg, null)) { - log(null, getFQCN(), Level.TRACE, msg, null); - } - } - - /** - * Log a message with the specific Marker at the DEBUG level. - * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void debug(Message msg, Throwable t) { - if (isEnabled(Level.TRACE, null, msg, t)) { - log(null, getFQCN(), Level.TRACE, msg, t); + log(null, getFQCN(), Level.TRACE, msg); } } @@ -537,20 +500,7 @@ public abstract class AbstractLogger implements Logger { */ public void debug(Marker marker, Message msg) { if (isEnabled(Level.DEBUG, marker, msg, null)) { - log(marker, getFQCN(), Level.DEBUG, msg, null); - } - } - - /** - * Log a message with the specific Marker at the DEBUG level. - * - * @param marker the marker data specific to this log statement. - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void debug(Marker marker, Message msg, Throwable t) { - if (isEnabled(Level.DEBUG, marker, msg, t)) { - log(marker, getFQCN(), Level.DEBUG, msg, t); + log(marker, getFQCN(), Level.DEBUG, msg); } } @@ -561,7 +511,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(String message) { if (isEnabled(Level.INFO, null, message)) { - log(null, getFQCN(), Level.INFO, new SimpleMessage(message), null); + log(null, getFQCN(), Level.INFO, new SimpleMessage(message)); } } @@ -573,7 +523,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Marker marker, String message) { if (isEnabled(Level.INFO, marker, message)) { - log(marker, getFQCN(), Level.INFO, new SimpleMessage(message), null); + log(marker, getFQCN(), Level.INFO, new SimpleMessage(message)); } } @@ -586,7 +536,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(String message, Throwable t) { if (isEnabled(Level.INFO, null, message, t)) { - log(null, getFQCN(), Level.INFO, new SimpleMessage(message), t); + log(null, getFQCN(), Level.INFO, new SimpleMessage(message, t)); } } @@ -600,7 +550,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Marker marker, String message, Throwable t) { if (isEnabled(Level.INFO, marker, message, t)) { - log(marker, getFQCN(), Level.INFO, new SimpleMessage(message), t); + log(marker, getFQCN(), Level.INFO, new SimpleMessage(message, t)); } } @@ -611,7 +561,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Object message) { if (isEnabled(Level.INFO, null, message, null)) { - log(null, getFQCN(), Level.INFO, new ObjectMessage(message), null); + log(null, getFQCN(), Level.INFO, new ObjectMessage(message)); } } @@ -623,7 +573,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Marker marker, Object message) { if (isEnabled(Level.INFO, marker, message, null)) { - log(marker, getFQCN(), Level.INFO, new ObjectMessage(message), null); + log(marker, getFQCN(), Level.INFO, new ObjectMessage(message)); } } @@ -636,7 +586,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Object message, Throwable t) { if (isEnabled(Level.INFO, null, message, t)) { - log(null, getFQCN(), Level.INFO, new ObjectMessage(message), t); + log(null, getFQCN(), Level.INFO, new ObjectMessage(message, t)); } } @@ -651,7 +601,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Marker marker, Object message, Throwable t) { if (isEnabled(Level.INFO, marker, message, t)) { - log(marker, getFQCN(), Level.INFO, new ObjectMessage(message), t); + log(marker, getFQCN(), Level.INFO, new ObjectMessage(message, t)); } } @@ -663,7 +613,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(String message, Object... params) { if (isEnabled(Level.INFO, null, message, params)) { - log(null, getFQCN(), Level.INFO, new ParameterizedMessage(message, params), null); + log(null, getFQCN(), Level.INFO, new ParameterizedMessage(message, params)); } } @@ -676,7 +626,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Marker marker, String message, Object... params) { if (isEnabled(Level.INFO, marker, message, params)) { - log(marker, getFQCN(), Level.INFO, new ParameterizedMessage(message, params), null); + log(marker, getFQCN(), Level.INFO, new ParameterizedMessage(message, params)); } } @@ -707,19 +657,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Message msg) { if (isEnabled(Level.INFO, null, msg, null)) { - log(null, getFQCN(), Level.INFO, msg, null); - } - } - - /** - * Log a message with the specific Marker at the INFO level. - * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void info(Message msg, Throwable t) { - if (isEnabled(Level.INFO, null, msg, t)) { - log(null, getFQCN(), Level.INFO, msg, t); + log(null, getFQCN(), Level.INFO, msg); } } @@ -731,20 +669,7 @@ public abstract class AbstractLogger implements Logger { */ public void info(Marker marker, Message msg) { if (isEnabled(Level.INFO, null, msg, null)) { - log(marker, getFQCN(), Level.INFO, msg, null); - } - } - - /** - * Log a message with the specific Marker at the INFO level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void info(Marker marker, Message msg, Throwable t) { - if (isEnabled(Level.INFO, marker, msg, t)) { - log(marker, getFQCN(), Level.INFO, msg, t); + log(marker, getFQCN(), Level.INFO, msg); } } @@ -755,7 +680,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(String message) { if (isEnabled(Level.WARN, null, message)) { - log(null, getFQCN(), Level.WARN, new SimpleMessage(message), null); + log(null, getFQCN(), Level.WARN, new SimpleMessage(message)); } } @@ -767,7 +692,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Marker marker, String message) { if (isEnabled(Level.WARN, marker, message)) { - log(marker, getFQCN(), Level.WARN, new SimpleMessage(message), null); + log(marker, getFQCN(), Level.WARN, new SimpleMessage(message)); } } @@ -780,7 +705,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(String message, Throwable t) { if (isEnabled(Level.WARN, null, message, t)) { - log(null, getFQCN(), Level.DEBUG, new SimpleMessage(message), t); + log(null, getFQCN(), Level.DEBUG, new SimpleMessage(message, t)); } } @@ -794,7 +719,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Marker marker, String message, Throwable t) { if (isEnabled(Level.WARN, marker, message, t)) { - log(marker, getFQCN(), Level.DEBUG, new SimpleMessage(message), t); + log(marker, getFQCN(), Level.DEBUG, new SimpleMessage(message, t)); } } @@ -806,7 +731,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Marker marker, Object message) { if (isEnabled(Level.WARN, marker, message, null)) { - log(marker, getFQCN(), Level.WARN, new ObjectMessage(message), null); + log(marker, getFQCN(), Level.WARN, new ObjectMessage(message)); } } @@ -817,7 +742,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Object message) { if (isEnabled(Level.WARN, null, message, null)) { - log(null, getFQCN(), Level.WARN, new ObjectMessage(message), null); + log(null, getFQCN(), Level.WARN, new ObjectMessage(message)); } } @@ -830,7 +755,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Object message, Throwable t) { if (isEnabled(Level.WARN, null, message, t)) { - log(null, getFQCN(), Level.DEBUG, new ObjectMessage(message), t); + log(null, getFQCN(), Level.DEBUG, new ObjectMessage(message, t)); } } @@ -844,7 +769,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Marker marker, Object message, Throwable t) { if (isEnabled(Level.WARN, marker, message, t)) { - log(marker, getFQCN(), Level.DEBUG, new ObjectMessage(message), t); + log(marker, getFQCN(), Level.DEBUG, new ObjectMessage(message, t)); } } @@ -856,7 +781,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(String message, Object... params) { if (isEnabled(Level.WARN, null, message, params)) { - log(null, getFQCN(), Level.WARN, new ParameterizedMessage(message, params), null); + log(null, getFQCN(), Level.WARN, new ParameterizedMessage(message, params)); } } @@ -869,7 +794,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Marker marker, String message, Object... params) { if (isEnabled(Level.WARN, marker, message, params)) { - log(marker, getFQCN(), Level.WARN, new ParameterizedMessage(message, params), null); + log(marker, getFQCN(), Level.WARN, new ParameterizedMessage(message, params)); } } @@ -901,19 +826,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Message msg) { if (isEnabled(Level.WARN, null, msg, null)) { - log(null, getFQCN(), Level.WARN, msg, null); - } - } - - /** - * Log a message with the specific Marker at the WARN level. - * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void warn(Message msg, Throwable t) { - if (isEnabled(Level.WARN, null, msg, t)) { - log(null, getFQCN(), Level.WARN, msg, t); + log(null, getFQCN(), Level.WARN, msg); } } @@ -925,20 +838,7 @@ public abstract class AbstractLogger implements Logger { */ public void warn(Marker marker, Message msg) { if (isEnabled(Level.WARN, null, msg, null)) { - log(marker, getFQCN(), Level.WARN, msg, null); - } - } - - /** - * Log a message with the specific Marker at the WARN level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void warn(Marker marker, Message msg, Throwable t) { - if (isEnabled(Level.WARN, marker, msg, t)) { - log(marker, getFQCN(), Level.WARN, msg, t); + log(marker, getFQCN(), Level.WARN, msg); } } @@ -949,7 +849,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(String message) { if (isEnabled(Level.ERROR, null, message)) { - log(null, getFQCN(), Level.ERROR, new SimpleMessage(message), null); + log(null, getFQCN(), Level.ERROR, new SimpleMessage(message)); } } @@ -961,7 +861,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Marker marker, String message) { if (isEnabled(Level.ERROR, marker, message)) { - log(marker, getFQCN(), Level.ERROR, new SimpleMessage(message), null); + log(marker, getFQCN(), Level.ERROR, new SimpleMessage(message)); } } @@ -974,7 +874,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(String message, Throwable t) { if (isEnabled(Level.ERROR, null, message, t)) { - log(null, getFQCN(), Level.ERROR, new SimpleMessage(message), t); + log(null, getFQCN(), Level.ERROR, new SimpleMessage(message, t)); } } @@ -988,7 +888,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Marker marker, String message, Throwable t) { if (isEnabled(Level.ERROR, marker, message, t)) { - log(marker, getFQCN(), Level.ERROR, new SimpleMessage(message), t); + log(marker, getFQCN(), Level.ERROR, new SimpleMessage(message, t)); } } @@ -999,7 +899,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Object message) { if (isEnabled(Level.ERROR, null, message, null)) { - log(null, getFQCN(), Level.ERROR, new ObjectMessage(message), null); + log(null, getFQCN(), Level.ERROR, new ObjectMessage(message)); } } @@ -1011,7 +911,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Marker marker, Object message) { if (isEnabled(Level.ERROR, marker, message, null)) { - log(marker, getFQCN(), Level.ERROR, new ObjectMessage(message), null); + log(marker, getFQCN(), Level.ERROR, new ObjectMessage(message)); } } @@ -1024,7 +924,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Object message, Throwable t) { if (isEnabled(Level.ERROR, null, message, t)) { - log(null, getFQCN(), Level.ERROR, new ObjectMessage(message), t); + log(null, getFQCN(), Level.ERROR, new ObjectMessage(message, t)); } } @@ -1038,7 +938,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Marker marker, Object message, Throwable t) { if (isEnabled(Level.ERROR, marker, message, t)) { - log(marker, getFQCN(), Level.ERROR, new ObjectMessage(message), t); + log(marker, getFQCN(), Level.ERROR, new ObjectMessage(message, t)); } } @@ -1050,7 +950,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(String message, Object... params) { if (isEnabled(Level.ERROR, null, message, params)) { - log(null, getFQCN(), Level.ERROR, new ParameterizedMessage(message, params), null); + log(null, getFQCN(), Level.ERROR, new ParameterizedMessage(message, params)); } } @@ -1063,7 +963,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Marker marker, String message, Object... params) { if (isEnabled(Level.ERROR, marker, message, params)) { - log(marker, getFQCN(), Level.ERROR, new ParameterizedMessage(message, params), null); + log(marker, getFQCN(), Level.ERROR, new ParameterizedMessage(message, params)); } } @@ -1096,19 +996,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Message msg) { if (isEnabled(Level.ERROR, null, msg, null)) { - log(null, getFQCN(), Level.ERROR, msg, null); - } - } - - /** - * Log a message with the specific Marker at the ERROR level. - * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void error(Message msg, Throwable t) { - if (isEnabled(Level.ERROR, null, msg, t)) { - log(null, getFQCN(), Level.ERROR, msg, t); + log(null, getFQCN(), Level.ERROR, msg); } } @@ -1120,20 +1008,7 @@ public abstract class AbstractLogger implements Logger { */ public void error(Marker marker, Message msg) { if (isEnabled(Level.ERROR, null, msg, null)) { - log(null, getFQCN(), Level.ERROR, msg, null); - } - } - - /** - * Log a message with the specific Marker at the ERROR level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void error(Marker marker, Message msg, Throwable t) { - if (isEnabled(Level.TRACE, marker, msg, t)) { - log(marker, getFQCN(), Level.TRACE, msg, t); + log(null, getFQCN(), Level.ERROR, msg); } } @@ -1144,7 +1019,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(String message) { if (isEnabled(Level.FATAL, null, message)) { - log(null, getFQCN(), Level.FATAL, new SimpleMessage(message), null); + log(null, getFQCN(), Level.FATAL, new SimpleMessage(message)); } } @@ -1157,7 +1032,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Marker marker, String message) { if (isEnabled(Level.FATAL, marker, message)) { - log(marker, getFQCN(), Level.FATAL, new SimpleMessage(message), null); + log(marker, getFQCN(), Level.FATAL, new SimpleMessage(message)); } } @@ -1170,7 +1045,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(String message, Throwable t) { if (isEnabled(Level.FATAL, null, message, t)) { - log(null, getFQCN(), Level.FATAL, new SimpleMessage(message), t); + log(null, getFQCN(), Level.FATAL, new SimpleMessage(message, t)); } } @@ -1184,7 +1059,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Marker marker, String message, Throwable t) { if (isEnabled(Level.FATAL, marker, message, t)) { - log(marker, getFQCN(), Level.FATAL, new SimpleMessage(message), t); + log(marker, getFQCN(), Level.FATAL, new SimpleMessage(message, t)); } } @@ -1195,7 +1070,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Object message) { if (isEnabled(Level.FATAL, null, message, null)) { - log(null, getFQCN(), Level.FATAL, new ObjectMessage(message), null); + log(null, getFQCN(), Level.FATAL, new ObjectMessage(message)); } } @@ -1207,7 +1082,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Marker marker, Object message) { if (isEnabled(Level.FATAL, marker, message, null)) { - log(marker, getFQCN(), Level.FATAL, new ObjectMessage(message), null); + log(marker, getFQCN(), Level.FATAL, new ObjectMessage(message)); } } @@ -1220,7 +1095,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Object message, Throwable t) { if (isEnabled(Level.FATAL, null, message, t)) { - log(null, getFQCN(), Level.FATAL, new ObjectMessage(message), t); + log(null, getFQCN(), Level.FATAL, new ObjectMessage(message, t)); } } @@ -1234,7 +1109,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Marker marker, Object message, Throwable t) { if (isEnabled(Level.FATAL, marker, message, t)) { - log(marker, getFQCN(), Level.FATAL, new ObjectMessage(message), t); + log(marker, getFQCN(), Level.FATAL, new ObjectMessage(message, t)); } } @@ -1246,7 +1121,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(String message, Object... params) { if (isEnabled(Level.FATAL, null, message, params)) { - log(null, getFQCN(), Level.FATAL, new ParameterizedMessage(message, params), null); + log(null, getFQCN(), Level.FATAL, new ParameterizedMessage(message, params)); } } @@ -1259,7 +1134,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Marker marker, String message, Object... params) { if (isEnabled(Level.FATAL, marker, message, params)) { - log(marker, getFQCN(), Level.FATAL, new ParameterizedMessage(message, params), null); + log(marker, getFQCN(), Level.FATAL, new ParameterizedMessage(message, params)); } } @@ -1291,19 +1166,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Message msg) { if (isEnabled(Level.FATAL, null, msg, null)) { - log(null, getFQCN(), Level.FATAL, msg, null); - } - } - - /** - * Log a message with the specific Marker at the FATAL level. - * - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void fatal(Message msg, Throwable t) { - if (isEnabled(Level.FATAL, null, msg, t)) { - log(null, getFQCN(), Level.FATAL, msg, t); + log(null, getFQCN(), Level.FATAL, msg); } } @@ -1315,20 +1178,7 @@ public abstract class AbstractLogger implements Logger { */ public void fatal(Marker marker, Message msg) { if (isEnabled(Level.FATAL, null, msg, null)) { - log(null, getFQCN(), Level.FATAL, msg, null); - } - } - - /** - * Log a message with the specific Marker at the FATAL level. - * - * @param marker the marker data specific to this log statement - * @param msg the message string to be logged - * @param t A Throwable or null. - */ - public void fatal(Marker marker, Message msg, Throwable t) { - if (isEnabled(Level.FATAL, marker, msg, t)) { - log(marker, getFQCN(), Level.FATAL, msg, t); + log(null, getFQCN(), Level.FATAL, msg); } } @@ -1341,7 +1191,7 @@ public abstract class AbstractLogger implements Logger { * @param data The Message. * @param t A Throwable or null. */ - protected abstract void log(Marker marker, String fqcn, Level level, Message data, Throwable t); + protected abstract void log(Marker marker, String fqcn, Level level, Message data); /* * Instead of one single method with Object... declared the following methods explicitly specify @@ -1434,7 +1284,7 @@ public abstract class AbstractLogger implements Logger { * @param t A Throwable. * @return True if logging is enabled, false otherwise. */ - protected abstract boolean isEnabled(Level level, Marker marker, Message data, Throwable t); + protected abstract boolean isEnabled(Level level, Marker marker, Message data); private Message entryMsg(int count, Object... params) { if (count == 0) { diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java b/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java index 65c875a..3a29be6 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java @@ -53,8 +53,8 @@ public class AbstractLoggerWrapper extends AbstractLogger { * @param t A Throwable or null. */ @Override - public void log(Marker marker, String fqcn, Level level, Message data, Throwable t) { - logger.log(marker, fqcn, level, data, t); + public void log(Marker marker, String fqcn, Level level, Message data) { + logger.log(marker, fqcn, level, data); } /** @@ -159,11 +159,10 @@ public class AbstractLoggerWrapper extends AbstractLogger { * @param level The logging Level to check. * @param marker A Marker or null. * @param data The Message. - * @param t A Throwable. * @return true if the event would be logged for the Level, Marker, Message and Throwable, false otherwise. */ @Override - public boolean isEnabled(Level level, Marker marker, Message data, Throwable t) { - return logger.isEnabled(level, marker, data, t); + public boolean isEnabled(Level level, Marker marker, Message data) { + return logger.isEnabled(level, marker, data); } } diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusData.java b/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusData.java index 6921cd4..b3a4cde 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusData.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusData.java @@ -37,8 +37,6 @@ public class StatusData { private final Message msg; - private final Throwable throwable; - /** * Creates the StatusData object. * @param caller The method that created the event. @@ -46,12 +44,11 @@ public class StatusData { * @param msg The message String. * @param t The Error or Exception that occurred. */ - public StatusData(StackTraceElement caller, Level level, Message msg, Throwable t) { + public StatusData(StackTraceElement caller, Level level, Message msg) { this.timestamp = System.currentTimeMillis(); this.caller = caller; this.level = level; this.msg = msg; - this.throwable = t; } /** @@ -87,14 +84,6 @@ public class StatusData { } /** - * Returns the Throwable associated with the event. - * @return The Throwable associated with the event. - */ - public Throwable getThrowable() { - return throwable; - } - - /** * Formats the StatusData for viewing. * @return The formatted status data as a String. */ @@ -108,10 +97,10 @@ public class StatusData { sb.append(msg.getFormattedMessage()); Object[] params = msg.getParameters(); Throwable t; - if (throwable == null && params != null && params[params.length - 1] instanceof Throwable) { + if (msg.getThrowable() == null && params != null && params[params.length - 1] instanceof Throwable) { t = (Throwable) params[params.length - 1]; } else { - t = throwable; + t = msg.getThrowable(); } if (t != null) { sb.append(" "); diff --git a/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java b/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java index 098d7d4..6f89ae5 100644 --- a/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java +++ b/log4j2-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java @@ -146,12 +146,12 @@ public final class StatusLogger extends AbstractLogger { * @param t A Throwable or null. */ @Override - public void log(Marker marker, String fqcn, Level level, Message msg, Throwable t) { + public void log(Marker marker, String fqcn, Level level, Message msg) { StackTraceElement element = null; if (fqcn != null) { element = getStackTraceElement(fqcn, Thread.currentThread().getStackTrace()); } - StatusData data = new StatusData(element, level, msg, t); + StatusData data = new StatusData(element, level, msg); msgLock.lock(); try { messages.add(data); @@ -219,7 +219,7 @@ public final class StatusLogger extends AbstractLogger { } @Override - protected boolean isEnabled(Level level, Marker marker, Message data, Throwable t) { + protected boolean isEnabled(Level level, Marker marker, Message data) { return isEnabled(level, marker); } diff --git a/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLogger.java b/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLogger.java index ea6bc7f..0d3fc52 100644 --- a/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLogger.java +++ b/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLogger.java @@ -33,7 +33,7 @@ public class SimpleLogger extends AbstractLogger { } @Override - public void log(Marker marker, String fqcn, Level level, Message msg, Throwable throwable) { + public void log(Marker marker, String fqcn, Level level, Message msg) { StringBuilder sb = new StringBuilder(); sb.append(" "); sb.append(level.toString()); @@ -47,10 +47,10 @@ public class SimpleLogger extends AbstractLogger { } Object[] params = msg.getParameters(); Throwable t; - if (throwable == null && params != null && params[params.length -1] instanceof Throwable ) { + if (msg.getThrowable() == null && params != null && params[params.length -1] instanceof Throwable ) { t = (Throwable) params[params.length - 1]; } else { - t = throwable; + t = msg.getThrowable(); } if (t != null) { sb.append(" "); @@ -99,7 +99,7 @@ public class SimpleLogger extends AbstractLogger { } @Override - protected boolean isEnabled(Level level, Marker marker, Message msg, Throwable t) { + protected boolean isEnabled(Level level, Marker marker, Message msg) { return true; } } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/AbstractServer.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/AbstractServer.java index 692c354..2e8c7d8 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/AbstractServer.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/AbstractServer.java @@ -31,7 +31,8 @@ public class AbstractServer { protected void log(LogEvent event) { Logger logger = context.getLogger(event.getLoggerName()); - if (logger.config.filter(event.getLevel(), event.getMarker(), event.getMessage(), event.getThrown())) { + Throwable t = event.getMessage() == null ? null : event.getMessage().getThrowable(); + if (logger.config.filter(event.getLevel(), event.getMarker(), event.getMessage(), t)) { logger.config.logEvent(event); } } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/Filter.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/Filter.java index 00eeab0..9c2b952 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/Filter.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/Filter.java @@ -38,7 +38,7 @@ public interface Filter { Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t); - Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t); + Result filter(Logger logger, Level level, Marker marker, Message msg); Result filter(LogEvent event); diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java index 8f29265..57e014b 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java @@ -41,19 +41,18 @@ public class Log4jLogEvent implements LogEvent, Serializable { private final String name; private final Message message; private final long timestamp; - private final Throwable throwable; private final Map mdc; private final Stack ndc; private String threadName = null; private StackTraceElement location; - public Log4jLogEvent(String loggerName, Marker marker, String fqcn, Level level, Message message, Throwable t) { - this(loggerName, marker, fqcn, level, message, t, ThreadContext.getContext(), ThreadContext.cloneStack(), null, + public Log4jLogEvent(String loggerName, Marker marker, String fqcn, Level level, Message message) { + this(loggerName, marker, fqcn, level, message, ThreadContext.getContext(), ThreadContext.cloneStack(), null, null, System.currentTimeMillis()); } - public Log4jLogEvent(String loggerName, Marker marker, String fqcn, Level level, Message message, Throwable t, + public Log4jLogEvent(String loggerName, Marker marker, String fqcn, Level level, Message message, Map mdc, Stack ndc, String threadName, StackTraceElement location, long timestamp) { name = loggerName; @@ -61,7 +60,6 @@ public class Log4jLogEvent implements LogEvent, Serializable { this.fqcnOfLogger = fqcn; this.level = level; this.message = message; - this.throwable = t; this.mdc = mdc; this.ndc = ndc; this.timestamp = timestamp; @@ -95,10 +93,6 @@ public class Log4jLogEvent implements LogEvent, Serializable { return timestamp; } - public Throwable getThrown() { - return throwable; - } - public Marker getMarker() { return marker; } @@ -178,7 +172,6 @@ public class Log4jLogEvent implements LogEvent, Serializable { private final String name; private final Message message; private final long timestamp; - private final Throwable throwable; private final HashMap mdc; private final Stack ndc; private String threadName; @@ -191,7 +184,6 @@ public class Log4jLogEvent implements LogEvent, Serializable { this.name = event.name; this.message = event.message; this.timestamp = event.timestamp; - this.throwable = event.throwable; this.mdc = new HashMap(event.mdc); this.ndc = event.ndc; this.location = event.getSource(); @@ -199,7 +191,7 @@ public class Log4jLogEvent implements LogEvent, Serializable { } protected Object readResolve() { - return new Log4jLogEvent(name, marker, fqcnOfLogger, level, message, throwable, mdc, ndc, threadName, + return new Log4jLogEvent(name, marker, fqcnOfLogger, level, message, mdc, ndc, threadName, location, timestamp); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java index e18bca1..ded42cd 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java @@ -78,13 +78,6 @@ public interface LogEvent extends Serializable { /** - * Get throwable associated with logging request. - * @return throwable, may be null. - */ - Throwable getThrown(); - - - /** * Get the MDC data. * * @return A copy of the Mapped Diagnostic Context or null. diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEventFactory.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEventFactory.java index cd83055..b8d06dc 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEventFactory.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEventFactory.java @@ -26,5 +26,5 @@ import org.apache.logging.log4j.message.Message; */ public interface LogEventFactory { - LogEvent createEvent(String loggerName, Marker marker, String fqcn, Level level, Message data, Throwable t); + LogEvent createEvent(String loggerName, Marker marker, String fqcn, Level level, Message data); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/Logger.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/Logger.java index 1940da9..80497d0 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/Logger.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/Logger.java @@ -83,8 +83,8 @@ public class Logger extends AbstractLogger { } @Override - protected void log(Marker marker, String fqcn, Level level, Message data, Throwable t) { - config.loggerConfig.log(name, marker, fqcn, level, data, t); + protected void log(Marker marker, String fqcn, Level level, Message data) { + config.loggerConfig.log(name, marker, fqcn, level, data); } @Override @@ -124,8 +124,8 @@ public class Logger extends AbstractLogger { } @Override - protected boolean isEnabled(Level level, Marker marker, Message msg, Throwable t) { - return config.filter(level, marker, msg, t); + protected boolean isEnabled(Level level, Marker marker, Message msg) { + return config.filter(level, marker, msg); } public void addAppender(Appender appender) { @@ -317,12 +317,12 @@ public class Logger extends AbstractLogger { return intLevel >= level.intLevel(); } - boolean filter(Level level, Marker marker, Message msg, Throwable t) { + boolean filter(Level level, Marker marker, Message msg) { if (config.hasFilters()) { Iterator iter = config.getFilters(); while (iter.hasNext()) { Filter filter = iter.next(); - Filter.Result r = filter.filter(logger, level, marker, msg, t); + Filter.Result r = filter.filter(logger, level, marker, msg); if (r != Filter.Result.NEUTRAL) { return r == Filter.Result.ACCEPT; } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java index 97c8a7a..fd8ede6 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java @@ -208,10 +208,6 @@ class FlumeEvent extends EventBaseImpl implements LogEvent { return event.getMillis(); } - public Throwable getThrown() { - return event.getThrown(); - } - public Map getContextMap() { return ctx; } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java index 4a6d2af..cc15abe 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java @@ -149,8 +149,8 @@ public class LoggerConfig extends Filterable implements LogEventFactory { this.additive = additive; } - public void log(String loggerName, Marker marker, String fqcn, Level level, Message data, Throwable t) { - LogEvent event = logEventFactory.createEvent(loggerName, marker, fqcn, level, data, t); + public void log(String loggerName, Marker marker, String fqcn, Level level, Message data) { + LogEvent event = logEventFactory.createEvent(loggerName, marker, fqcn, level, data); log(event); } @@ -173,9 +173,8 @@ public class LoggerConfig extends Filterable implements LogEventFactory { } } - public LogEvent createEvent(String loggerName, Marker marker, String fqcn, Level level, Message data, - Throwable t) { - return new Log4jLogEvent(loggerName, marker, fqcn, level, data, t); + public LogEvent createEvent(String loggerName, Marker marker, String fqcn, Level level, Message data) { + return new Log4jLogEvent(loggerName, marker, fqcn, level, data); } public String toString() { diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java index e7e7ea0..ac20284 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/DynamicThresholdFilter.java @@ -61,7 +61,8 @@ public class DynamicThresholdFilter extends FilterBase { return filter(level); } - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + @Override + public Result filter(Logger logger, Level level, Marker marker, Message msg) { return filter(level); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java index d7acc8a..2189b94 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/FilterBase.java @@ -112,7 +112,7 @@ public abstract class FilterBase implements Filter, Lifecycle { * @param t * @return */ - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + public Result filter(Logger logger, Level level, Marker marker, Message msg) { return Result.NEUTRAL; } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java index d78c6a2..b884ebe 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MarkerFilter.java @@ -51,7 +51,8 @@ public class MarkerFilter extends FilterBase { return filter(marker); } - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + @Override + public Result filter(Logger logger, Level level, Marker marker, Message msg) { return filter(marker); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java index 6b961cf..d7d8919 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java @@ -56,7 +56,8 @@ public class RegexFilter extends FilterBase { return filter(msg.toString()); } - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + @Override + public Result filter(Logger logger, Level level, Marker marker, Message msg) { String text = useRawMessage ? msg.getMessageFormat() : msg.getFormattedMessage(); return filter(text); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java index fe187fb..106552d 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java @@ -48,7 +48,7 @@ public class StructuredDataFilter extends FilterBase { } @Override - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + public Result filter(Logger logger, Level level, Marker marker, Message msg) { if (msg instanceof StructuredDataMessage) { return filter((StructuredDataMessage)msg); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java index c7ab503..18d5db4 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java @@ -56,7 +56,7 @@ public class ThreadContextMapFilter extends FilterBase { } @Override - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + public Result filter(Logger logger, Level level, Marker marker, Message msg) { return filter(); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java index 835e8aa..7ed8d27 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThresholdFilter.java @@ -53,7 +53,8 @@ public class ThresholdFilter extends FilterBase { return filter(level); } - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { + @Override + public Result filter(Logger logger, Level level, Marker marker, Message msg) { return filter(level); } diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java index 7166bd3..d38f99d 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/HTMLLayout.java @@ -129,7 +129,7 @@ public class HTMLLayout extends AbstractStringLayout { sbuf.append("").append(LINE_SEP); } - Throwable throwable = event.getThrown(); + Throwable throwable = event.getMessage() == null ? null : event.getMessage().getThrowable(); if (throwable != null) { sbuf.append(""); appendThrowableAsHTML(throwable, sbuf); diff --git a/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java b/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java index 2a04a13..e81c6dc 100644 --- a/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java +++ b/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java @@ -118,7 +118,7 @@ public class XMLLayout extends AbstractStringLayout { buf.append("]]>\r\n"); } - Throwable throwable = event.getThrown(); + Throwable throwable = event.getMessage() == null ? null : event.getMessage().getThrowable(); if (throwable != null) { List s = getThrowableString(throwable); buf.append("