logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1051418 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j2-api/src/main/java/org/apache/logging/log4j/message/ log4j2-core/src/main/java/org/apache/logging/log4j/core/ log4j2-core/src/main/java/org/apache/logging/log4j/cor...
Date Tue, 21 Dec 2010 08:50:25 GMT
Author: rgoers
Date: Tue Dec 21 08:50:25 2010
New Revision: 1051418

URL: http://svn.apache.org/viewvc?rev=1051418&view=rev
Log:
Get rid of message hints

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LoggerNameAwareMessage.java
Removed:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MessageHint.java
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/pattern/MessagePatternConverter.java

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java?rev=1051418&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java
(added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/FormattedMessage.java
Tue Dec 21 08:50:25 2010
@@ -0,0 +1,11 @@
+package org.apache.logging.log4j.message;
+
+/**
+ *
+ */
+public interface FormattedMessage extends Message
+{
+    void setFormat(String format);
+
+    String getFormat();
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.java
Tue Dec 21 08:50:25 2010
@@ -16,18 +16,18 @@
  */
 package org.apache.logging.log4j.message;
 
+import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.internal.StatusLogger;
 
-import java.util.HashMap;
 import java.util.Locale;
-import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
 /**
  *
  */
-public class LocalizedMessage extends ParameterizedMessage {
+public class LocalizedMessage extends ParameterizedMessage implements LoggerNameAwareMessage
+{
 
     private String bundleId;
 
@@ -35,10 +35,10 @@ public class LocalizedMessage extends Pa
 
     private Locale locale;
 
-    private Map<MessageHint, String> hints = new HashMap<MessageHint, String>();
-
     private StatusLogger logger = StatusLogger.getLogger();
 
+    private String loggerName = null;
+
     public LocalizedMessage() {
         super();
         setup(null, null, null);
@@ -184,16 +184,20 @@ public class LocalizedMessage extends Pa
         setup(null, null, locale);
     }
 
+    public void setLoggerName(String name)
+    {
+        this.loggerName = name;
+    }
+
+    public String getLoggerName()
+    {
+        return this.loggerName;
+    }
+
     private void setup(String bundleId, ResourceBundle bundle, Locale locale) {
         this.bundleId = bundleId;
         this.bundle = bundle;
         this.locale = locale;
-        hints.put(MessageHint.LOGGER_NAME, "");
-    }
-
-    @Override
-    public Map<MessageHint, String> getHints() {
-        return hints;
     }
 
     @Override
@@ -203,8 +207,7 @@ public class LocalizedMessage extends Pa
             if (bundleId != null) {
                 bundle = getBundle(bundleId, locale, false);
             } else {
-                String key = hints.get(MessageHint.LOGGER_NAME);
-                bundle = getBundle(key, locale, true);
+                bundle = getBundle(loggerName, locale, true);
             }
         }
         String msgPattern = (bundle == null || !bundle.containsKey(messagePattern)) ?

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LoggerNameAwareMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LoggerNameAwareMessage.java?rev=1051418&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LoggerNameAwareMessage.java
(added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LoggerNameAwareMessage.java
Tue Dec 21 08:50:25 2010
@@ -0,0 +1,13 @@
+package org.apache.logging.log4j.message;
+
+import org.apache.logging.log4j.Logger;
+
+/**
+ *  Message that is interested in the name of the Logger.
+ */
+public interface LoggerNameAwareMessage
+{
+    void setLoggerName(String name);
+
+    String getLoggerName();
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java
Tue Dec 21 08:50:25 2010
@@ -55,18 +55,4 @@ public interface Message extends Seriali
      * @return An array of parameter values or null.
      */
     Object[] getParameters();
-
-
-    /**
-     * Returns a Map of data that the Message would like to aid in formatting. The
-     * Message will construct the map with the keys it is requesting the implementation to
-     * provide values for. The Message must be able to return a formatted message even if
-     * no hints are provided.
-     * @return The Message hints.
-     * @doubt would seem to go better into a formatter or format object. (RG) A Formatter
would have
-     * to understand every type of object that could be passed to it or you would have to
-     * configure an endless number of formatters on loggers and somehow pick the correct
one. A Message
-     * implementation formats based only on what can be placed into the Message and what
hints are provided.
-     */
-    Map<MessageHint, String> getHints();
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
Tue Dec 21 08:50:25 2010
@@ -45,10 +45,6 @@ public class ObjectMessage implements Me
         return new Object[]{obj};
     }
 
-    public Map<MessageHint, String> getHints() {
-        return null;
-    }
-
     public boolean equals(Object o) {
         if (this == o) {
             return true;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java
Tue Dec 21 08:50:25 2010
@@ -80,10 +80,6 @@ public class ParameterizedMessage implem
         this(messagePattern, new Object[]{arg1, arg2});
     }
 
-    public Map<MessageHint, String> getHints() {
-        return null;
-    }
-
     private void parseArguments(Object[] arguments) {
         int argsCount = countArgumentPlaceholders(messagePattern);
         int resultArgCount = arguments.length;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java
Tue Dec 21 08:50:25 2010
@@ -35,10 +35,6 @@ public class SimpleMessage implements Me
         this.message = message;
     }
 
-    public Map<MessageHint, String> getHints() {
-        return null;
-    }
-
     public String getFormattedMessage() {
         return message;
     }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
Tue Dec 21 08:50:25 2010
@@ -25,7 +25,7 @@ import java.util.Map;
 /**
  * Represents a Message that conforms to RFC 5424 (http://tools.ietf.org/html/rfc5424).
  */
-public class StructuredDataMessage implements Message, Serializable {
+public class StructuredDataMessage implements FormattedMessage, Serializable {
     private static final long serialVersionUID = 1703221292892071920L;
 
     public static final String FULL = "full";
@@ -38,28 +38,30 @@ public class StructuredDataMessage imple
 
     private String type;
 
-    private Map<MessageHint, String> hints = new HashMap<MessageHint, String>();
+    private String format = null;
 
     public StructuredDataMessage(final String id, final String msg, final String type) {
         this.id = new StructuredDataId(id, null, null);
         this.message = msg;
         this.type = type;
-        hints.put(MessageHint.FORMAT, "");
     }
 
     public StructuredDataMessage(final StructuredDataId id, final String msg, final String
type) {
         this.id = id;
         this.message = msg;
         this.type = type;
-        hints.put(MessageHint.FORMAT, "");
     }
 
     protected StructuredDataMessage() {
 
     }
 
-    public Map<MessageHint, String> getHints() {
-        return hints;   
+    public void setFormat(String format) {
+        this.format = format;
+    }
+
+    public String getFormat() {
+        return this.format;
     }
 
     public StructuredDataId getId() {

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java
Tue Dec 21 08:50:25 2010
@@ -19,8 +19,8 @@ package org.apache.logging.log4j.core;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.message.LoggerNameAwareMessage;
 import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.MessageHint;
 
 import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
@@ -67,9 +67,8 @@ public class Log4jLogEvent implements Lo
         this.timestamp = timestamp;
         this.threadName = threadName;
         this.location = location;
-        Map<MessageHint, String> hints = message.getHints();
-        if (hints != null && hints.containsKey(MessageHint.LOGGER_NAME)) {
-            hints.put(MessageHint.LOGGER_NAME, name);
+        if (message != null && message instanceof LoggerNameAwareMessage) {
+            ((LoggerNameAwareMessage) message).setLoggerName(name);
         }
     }
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/pattern/MessagePatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/pattern/MessagePatternConverter.java?rev=1051418&r1=1051417&r2=1051418&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/pattern/MessagePatternConverter.java
(original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/pattern/MessagePatternConverter.java
Tue Dec 21 08:50:25 2010
@@ -19,10 +19,8 @@ package org.apache.logging.log4j.core.la
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.message.FormattedMessage;
 import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.MessageHint;
-
-import java.util.Map;
 
 
 /**
@@ -58,9 +56,8 @@ public final class MessagePatternConvert
      */
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
         Message msg = event.getMessage();
-        Map<MessageHint, String> hints = msg.getHints();
-        if (hints != null && hints.containsKey(MessageHint.FORMAT)) {
-            hints.put(MessageHint.FORMAT, format);
+        if (msg != null && msg instanceof FormattedMessage) {
+            ((FormattedMessage) msg).setFormat(format);
         }
         toAppendTo.append(msg.getFormattedMessage());
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message