Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09BA19E5D for ; Wed, 25 Jan 2012 12:13:48 +0000 (UTC) Received: (qmail 43894 invoked by uid 500); 25 Jan 2012 12:13:47 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 43863 invoked by uid 500); 25 Jan 2012 12:13:47 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 43856 invoked by uid 99); 25 Jan 2012 12:13:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jan 2012 12:13:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jan 2012 12:13:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 23FBC238899C; Wed, 25 Jan 2012 12:13:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1235721 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j2-api/ log4j2-api/src/main/java/org/apache/logging/log4j/message/ log4j2-api/src/site/xdoc/ log4j2-api/src/test/java/org/apache/logging/log4j/message/ log4j2-core/sr... Date: Wed, 25 Jan 2012 12:13:24 -0000 To: commits@logging.apache.org From: rgoers@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120125121325.23FBC238899C@eris.apache.org> Author: rgoers Date: Wed Jan 25 12:13:24 2012 New Revision: 1235721 URL: http://svn.apache.org/viewvc?rev=1235721&view=rev Log: Start on API documentation Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/db/ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/api.xml - copied, changed from r1226512, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/site/xdoc/api.xml logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/messages.xml Removed: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/DeferredMessage.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/site/xdoc/api.xml Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/pom.xml logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/jmx.xml logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/layouts.xml logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/logsep.xml Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/pom.xml URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/pom.xml?rev=1235721&r1=1235720&r2=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/pom.xml (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/pom.xml Wed Jan 25 12:13:24 2012 @@ -33,6 +33,12 @@ + commons-httpclient + commons-httpclient + 3.1 + test + + junit junit 4.3.1 Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.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/MapMessage.java?rev=1235721&r1=1235720&r2=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java Wed Jan 25 12:13:24 2012 @@ -16,6 +16,10 @@ */ package org.apache.logging.log4j.message; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.io.ByteArrayOutputStream; import java.io.Serializable; import java.util.Collections; import java.util.HashMap; @@ -149,7 +153,7 @@ public class MapMessage implements Forma * @return The formatted String. */ public String asString() { - return asString(""); + return asString(format == null ? "" : format); } /** @@ -169,7 +173,12 @@ public class MapMessage implements Forma } public void asXML(StringBuilder sb) { - + sb.append("\n"); + SortedMap sorted = new TreeMap(data); + for (Map.Entry entry : sorted.entrySet()) { + sb.append(" ").append(entry.getValue()).append("\n"); + } + sb.append(""); } /** Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java?rev=1235721&r1=1235720&r2=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java Wed Jan 25 12:13:24 2012 @@ -35,4 +35,18 @@ public class MapMessageTest { String expected = "message=\"Test message {}\" project=\"Log4j\""; assertEquals(expected, result); } + + @Test + public void testXML() { + String testMsg = "Test message {}"; + MapMessage msg = new MapMessage(); + msg.setFormat("XML"); + msg.put("message", testMsg); + msg.put("project", "Log4j"); + String result = msg.getFormattedMessage(); + String expected = "\n Test message {}\n" + + " Log4j\n" + + ""; + assertEquals(expected, result); + } } Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml?rev=1235721&r1=1235720&r2=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml Wed Jan 25 12:13:24 2012 @@ -39,7 +39,6 @@ - @@ -47,6 +46,13 @@ + + + + + + + @@ -103,7 +109,6 @@ - Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/api.xml (from r1226512, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/site/xdoc/api.xml) URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/api.xml?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/api.xml&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/site/xdoc/api.xml&r1=1226512&r2=1235721&rev=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/site/xdoc/api.xml (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/api.xml Wed Jan 25 12:13:24 2012 @@ -24,19 +24,22 @@
- + +

The Log4Jj 2.0 API provides the interface that applications should code to and provides the adapter components required for implementers to create a logging implementation.

+
+
+ -
+ + + -
-

- The Log4j 2.0 API requires at least Java 5. -

-
+
+ \ No newline at end of file Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/jmx.xml URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/jmx.xml?rev=1235721&r1=1235720&r2=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/jmx.xml (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/jmx.xml Wed Jan 25 12:13:24 2012 @@ -18,13 +18,15 @@ - Overview + JMX Ralph Goers
- +

+ JMX support is incomplete at this time. Patches are welcome! +

\ No newline at end of file Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/layouts.xml URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/layouts.xml?rev=1235721&r1=1235720&r2=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/layouts.xml (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/layouts.xml Wed Jan 25 12:13:24 2012 @@ -586,7 +586,7 @@

As the name implies, the RFC5424Layout formats LogEvents in accordance with - RFC 5424, the enhanced Syslog specification. Although the specification + RFC 5424, the enhanced Syslog specification. Although the specification is primarily directed at sending messages via Syslog, this format is quite useful for other purposes since items are passed in the message as self-describing key/value pairs.

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/logsep.xml URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/logsep.xml?rev=1235721&r1=1235720&r2=1235721&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/logsep.xml (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/logsep.xml Wed Jan 25 12:13:24 2012 @@ -18,7 +18,7 @@ - Overview + Logging Separation Ralph Goers Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/messages.xml URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/messages.xml?rev=1235721&view=auto ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/messages.xml (added) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/messages.xml Wed Jan 25 12:13:24 2012 @@ -0,0 +1,155 @@ + + + + + + Log4J 2.0 API Messages + Ralph Goers + + + +
+ + +

+ Although Log4j 2 provides Logger methods that accept Strings and Objects, all of these are ulitmately + captured in Message objects that are then associated with the log event. Applications are free to + construct Messages of their own and pass them to the Logger. Although it may seem more expensive than + passing the message format and parameters directly to the event, testing has shown that with modern + JVMs the cost of creating and destroying events is minor, especially when complex tasks are encapsulated + in the Message instead of the application. In addition, when using the methods that accept Strings and + parameters, the underlying Message object will only be created if any configured global filters + or the Logger's log level allow the message to be processed. +

+

+ Consider an application that has a Map object containing {"Name" = "John Doe", "Address" = "123 Main + St.", + "Phone" = "(999) 555-1212"} and a User object that has a getId method that returns "jdoe". The developer + would like to add an informational message that returns "User John Doe has logged in using id jdoe". The + way this could be accomplished is by doing: +

+
+          logger.info("User {} has logged in using id {}, map.get("Name"), user.getId());
+        
+

+ While there is nothing inherently wrong with this, as the complexity of the objects and desired output + increases this technique becomes harder to use. As an alternative, using Messages allows: +

+
+          logger.info(new LoggedInMessage(map, user));
+        
+

+ In this alternative the formatting is delegated to the LoggedInMessage object's getFormattedMessage + method. + Although in this alternative a new object is created, none of the methods on the objects passed to the + LoggedInMessage are invoked until the LoggedInMessage is formatted. This is especially useful when an + Object's toString method does not produce the information you would like to appear in the log. +

+

+ Another advantage to Messages is that they simplify writing Layouts. In other logging frameworks the + Layout must loop through the parameters individually and determine what to do based on what objects + are encountered. With Messages the Layout has the option of delegating the formatting to the Message or + performing its formatting based on the type of Message encountered. +

+ +
+
+ +

+ A FormattedMessage will have setFormat and getFormat methods. The setFormat method may be called by a + Layout to provide advice on how the Message should be formatted. If the Message doesn't recognize the + format name it will simply format the data using its default format. An example of this is the + StructuredDataMessage which accepts a format String of "XML" which will cause it to format the event data + as XML instead of the RFC 5424 format. +

+
+
+ +

+ LocalizedMessage + is provided primarily to provide compatibility with Log4j 1.x. Generally, + the best approach to localization is to have the client UI render the events in the client's locale. +

+

+ LocalizedMessage extends a ParameterizedMessage by incorporating a ResourceBundle and allowing + the message pattern parameter to be the key to the message pattern in the bundle. If no bundle is specified, + LocalizedMessage will attempt to locate a bundle with the name of the Logger used to log the event. The + parameters to the Message will be incorporated into the Message whereever the "{}" placeholders occur. +

+ + + +

+ LoggerNameAwareMessage is an interface with a setLoggerName method. This method will be called during + event construction so that the Message has the name of the Logger used to log the event when the + message is being formatted. +

+
+
+ +

+ A MapMessage contains a Map of String keys and values. MapMessage implements FormattedMessage and accepts + a format specifier of "XML", in which case the Map will be formatted as XML. Otherwise, the Map will be + formatted as "key1=value1 key2=value2...". +

+
+
+ +

+ Formats an Object by calling its toString method. +

+
+
+ +

+ ParameterizedMessage + handles messages that contain "{}" in the format to represent replaceable tokens and the replacement + parameters. +

+ + + +

+ SimpleMessage contains a String that requires no formatting. +

+
+
+ +

+ StructuredDataMessage + allows applications to add items to a Map as well as set the id to allow a message to be formatted as a + Structured Data element in accordance with RFC 5424. +

+ + + +

+ A ThreadDumpMessage, if logged, will generate stack traces for all threads. If running on Java 6+ the + stack traces will include any locks that are held. +

+
+
+ +

+ A TimestampMessage will provide a getTimestamp method that is called during event construction. The + timestamp in the Message will be used in lieu of the current timestamp. +

+
+
+ +
\ No newline at end of file