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 6A5A573B4 for ; Sun, 13 Nov 2011 02:28:57 +0000 (UTC) Received: (qmail 79172 invoked by uid 500); 13 Nov 2011 02:28:57 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 79150 invoked by uid 500); 13 Nov 2011 02:28:57 -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 79143 invoked by uid 99); 13 Nov 2011 02:28:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Nov 2011 02:28:57 +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; Sun, 13 Nov 2011 02:28:47 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D47B323888FD; Sun, 13 Nov 2011 02:28:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1201395 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/ log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/ log4j2-core/src/main/jav... Date: Sun, 13 Nov 2011 02:28:24 -0000 To: commits@logging.apache.org From: rgoers@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111113022824.D47B323888FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rgoers Date: Sun Nov 13 02:28:23 2011 New Revision: 1201395 URL: http://svn.apache.org/viewvc?rev=1201395&view=rev Log: Added Layout documentation. Added tests to verify layouts. Added UUIDPatternConverter Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/package-info.java - copied, changed from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java - copied, changed from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java - copied, changed from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/UUIDUtil.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/UUIDPatternConverter.java - copied, changed from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/NameAbbreviatorTest.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/extending.xml Removed: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/UUIDUtil.java Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/flume/UUIDTest.java logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.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/layouts.xml Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.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/appender/flume/FlumeEvent.java?rev=1201395&r1=1201394&r2=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java Sun Nov 13 02:28:23 2011 @@ -21,6 +21,7 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LoggingException; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.helpers.UUIDUtil; import org.apache.logging.log4j.message.MapMessage; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.StructuredDataId; Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/package-info.java (from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.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/appender/rewrite/package-info.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/package-info.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.java&r1=1195339&r2=1201395&rev=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/package-info.java Sun Nov 13 02:28:23 2011 @@ -17,4 +17,4 @@ /** * Apache Flume Appender. Requires the user specifically include Flume and its dependencies. */ -package org.apache.logging.log4j.core.appender.flume; +package org.apache.logging.log4j.core.appender.rewrite; Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java (from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.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/appender/routing/package-info.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.java&r1=1195339&r2=1201395&rev=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/package-info.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/package-info.java Sun Nov 13 02:28:23 2011 @@ -17,4 +17,4 @@ /** * Apache Flume Appender. Requires the user specifically include Flume and its dependencies. */ -package org.apache.logging.log4j.core.appender.flume; +package org.apache.logging.log4j.core.appender.routing; Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java (from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/UUIDUtil.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/helpers/UUIDUtil.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/UUIDUtil.java&r1=1195339&r2=1201395&rev=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/UUIDUtil.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java Sun Nov 13 02:28:23 2011 @@ -14,7 +14,7 @@ * See the license for the specific language governing permissions and * limitations under the license. */ -package org.apache.logging.log4j.core.appender.flume; +package org.apache.logging.log4j.core.helpers; import org.apache.commons.lang.StringUtils; @@ -48,7 +48,7 @@ public abstract class UUIDUtil private static final int SEQUENCE_MASK = 0x3FFF; - static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; + public static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L; private static long uuidSequence = Long.getLong(UUID_SEQUENCE, 0); Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.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/PatternLayout.java?rev=1201395&r1=1201394&r2=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/PatternLayout.java Sun Nov 13 02:28:23 2011 @@ -43,353 +43,8 @@ import java.util.List; * pattern of the printf function in C. A conversion pattern is * composed of literal text and format control expressions called * conversion specifiers. - *

- *

Note that you are free to insert any literal text within the - * conversion pattern. - *

- *

- *

Each conversion specifier starts with a percent sign (%) and is - * followed by optional format modifiers and a conversion - * character. The conversion character specifies the type of - * data, e.g. category, priority, date, thread name. The format - * modifiers control such things as field width, padding, left and - * right justification. The following is a simple example. - *

- *

Let the conversion pattern be "%-5p [%t]: %m%n" and assume - * that the log4j environment was set to use a PatternLayout. Then the - * statements - *

- * Logger logger = LoggerFactory().getLogger("MyLogger");
- * logger.debug("Message 1");
- * logger.warn("Message 2");
- * 
- * would yield the output - *
- * DEBUG [main]: Message 1
- * WARN  [main]: Message 2
- * 
- *

- *

Note that there is no explicit separator between text and - * conversion specifiers. The pattern parser knows when it has reached - * the end of a conversion specifier when it reads a conversion - * character. In the example above the conversion specifier - * %-5p means the priority of the logging event should be left - * justified to a width of five characters. - *

- * The recognized conversion characters are - *

- *

- * - * - * - *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- *

- *

- *

- * - * - * - *

- *

- * - *

- *

- *

- *

- * - *

- *

- *

- *

- * - * - * - *

- *

- *

- *

- *

- *

- * - *

- *

- *

- * - *

- *

- *

- *

- *

- *

- *

- *

- *

- *

- * - *

- *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- * - *

- *

- *

- *

- *

- *

- * - *

- *

Conversion CharacterEffect
cUsed to output the category of the logging event. The - * category conversion specifier can be optionally followed by - * precision specifier, that is a decimal constant in - * brackets. - *

- *

If a precision specifier is given, then only the corresponding - * number of right most components of the category name will be - * printed. By default the category name is printed in full. - *

- *

For example, for the category name "a.b.c" the pattern - * %c{2} will output "b.c". - *

- *

CUsed to output the fully qualified class name of the caller - * issuing the logging request. This conversion specifier - * can be optionally followed by precision specifier, that - * is a decimal constant in brackets. - *

- *

If a precision specifier is given, then only the corresponding - * number of right most components of the class name will be - * printed. By default the class name is output in fully qualified form. - *

- *

For example, for the class name "org.apache.xyz.SomeClass", the - * pattern %C{1} will output "SomeClass". - *

- *

WARNING Generating the caller class information is - * slow. Thus, it's use should be avoided unless execution speed is - * not an issue. - *

- *

d Used to output the date of - * the logging event. The date conversion specifier may be - * followed by a set of braces containing a - * date and time pattern strings {@link java.text.SimpleDateFormat}, - * ABSOLUTE, DATE or ISO8601 - * and a set of braces containing a time zone id per - * {@link java.util.TimeZone#getTimeZone(String)}. - * For example, %d{HH:mm:ss,SSS}, - * %d{dd MMM yyyy HH:mm:ss,SSS}, - * %d{DATE} or %d{HH:mm:ss}{GMT+0}. If no date format specifier is given then - * ISO8601 format is assumed. - *
FUsed to output the file name where the logging request was - * issued. - *

- *

WARNING Generating caller location information is - * extremely slow. Its use should be avoided unless execution speed - * is not an issue. - *

- *

lUsed to output location information of the caller which generated - * the logging event. - *

- *

The location information depends on the JVM implementation but - * usually consists of the fully qualified name of the calling - * method followed by the callers source the file name and line - * number between parentheses. - *

- *

LUsed to output the line number from where the logging request - * was issued. - *

- *

mUsed to output the application supplied message associated with - * the logging event.
MUsed to output the method name where the logging request was - * issued. - *

- *

nOutputs the platform dependent line separator character or - * characters. - *

- *

This conversion character offers practically the same - * performance as using non-portable line separator strings such as - * "\n", or "\r\n". Thus, it is the preferred way of specifying a - * line separator. - *

- *

- *

pUsed to output the level of the logging event.
rUsed to output the number of milliseconds elapsed since the construction - * of the layout until the creation of the logging event.
tUsed to output the name of the thread that generated the logging event.
xUsed to output the NDC (nested diagnostic context) associated - * with the thread that generated the logging event. - *
X - *

- *

Used to output the MDC (mapped diagnostic context) associated - * with the thread that generated the logging event. The X - * conversion character can be followed by the key for the - * map placed between braces, as in %X{clientNumber} where - * clientNumber is the key. The value in the MDC - * corresponding to the key will be output. If no additional sub-option - * is specified, then the entire contents of the MDC key value pair set - * is output using a format {{key1,val1},{key2,val2}}

- *

- *

See {@link ThreadContext} class for more details. - *

- *

- *

properties - *

Used to output the Properties associated with the logging event. The properties - * conversion word can be followed by the key for the - * map placed between braces, as in %properties{application} where - * application is the key. The value in the Properties bundle - * corresponding to the key will be output. If no additional sub-option - * is specified, then the entire contents of the Properties key value pair set - * is output using a format {{key1,val1},{key2,val2}}

- *
throwable - *

Used to output the Throwable trace that has been bound to the LoggingEvent, by - * default this will output the full trace as one would normally find by a call to Throwable.printStackTrace(). - * The throwable conversion word can be followed by an option in the form %throwable{short} - * which will only output the first line of the Throwable.

- *
%The sequence %% outputs a single percent sign. - *
- *

- *

By default the relevant information is output as is. However, - * with the aid of format modifiers it is possible to change the - * minimum field width, the maximum field width and justification. - *

- *

The optional format modifier is placed between the percent sign - * and the conversion character. - *

- *

The first optional format modifier is the left justification - * flag which is just the minus (-) character. Then comes the - * optional minimum field width modifier. This is a decimal - * constant that represents the minimum number of characters to - * output. If the data item requires fewer characters, it is padded on - * either the left or the right until the minimum width is - * reached. The default is to pad on the left (right justify) but you - * can specify right padding with the left justification flag. The - * padding character is space. If the data item is larger than the - * minimum field width, the field is expanded to accommodate the - * data. The value is never truncated. - *

- *

This behavior can be changed using the maximum field - * width modifier which is designated by a period followed by a - * decimal constant. If the data item is longer than the maximum - * field, then the extra characters are removed from the - * beginning of the data item and not from the end. For - * example, it the maximum field width is eight and the data item is - * ten characters long, then the first two characters of the data item - * are dropped. This behavior deviates from the printf function in C - * where truncation is done from the end. - *

- *

Below are various format modifier examples for the category - * conversion specifier. - *

- *

- * - * - * - * - * - * - *

- *

- * - * - * - * - *

- *

- * - * - * - * - *

- *

- * - * - * - * - *

- *

Format modifier - * left justify - * minimum width - * maximum width - * comment - *

- *

%20cfalse20noneLeft pad with spaces if the category name is less than 20 - * characters long. - *

- *

%-20c true 20 none Right pad with - * spaces if the category name is less than 20 characters long. - *

- *

%.30cNAnone30Truncate from the beginning if the category name is longer than 30 - * characters. - *

- *

%20.30cfalse2030Left pad with spaces if the category name is shorter than 20 - * characters. However, if category name is longer than 30 characters, - * then truncate from the beginning. - *

- *

%-20.30ctrue2030Right pad with spaces if the category name is shorter than 20 - * characters. However, if category name is longer than 30 characters, - * then truncate from the beginning. - *

- *

- *

- *

Below are some examples of conversion patterns. - *

- *

- *

- *

%r [%t] %-5p %c %x - %m%n - *

This is essentially the TTCC layout. - *

- *

%-6r [%15.15t] %-5p %30.30c %x - %m%n - *

- *

Similar to the TTCC layout except that the relative time is - * right padded if less than 6 digits, thread name is right padded if - * less than 15 characters and truncated if longer and the category - * name is left padded if shorter than 30 characters and truncated if - * longer. - *

- *

- *

- *

The above text is largely inspired from Peter A. Darnell and - * Philip E. Margolis' highly recommended book "C -- a Software - * Engineering Approach", ISBN 0-387-97389-3. + * + * See the Log4j Manual for details on the supported pattern converters. */ @Plugin(name="PatternLayout",type="Core",elementType="layout",printObject=true) public class PatternLayout extends AbstractStringLayout { Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.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/XMLLayout.java?rev=1201395&r1=1201394&r2=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/layout/XMLLayout.java Sun Nov 13 02:28:23 2011 @@ -49,7 +49,7 @@ import org.apache.logging.log4j.core.Log * * <!DOCTYPE log4j:eventSet SYSTEM "log4j.dtd" [<!ENTITY data SYSTEM "abc">]> * - * <log4j:eventSet version="1.2" xmlns:log4j="http://jakarta.apache.org/log4j/"> + * <log4j:eventSet version="1.2" xmlns:log4j="http://logging.apache.org/log4j/"> *   &data; * </log4j:eventSet> * @@ -169,7 +169,7 @@ public class XMLLayout extends AbstractS } StringBuilder sbuf = new StringBuilder(); sbuf.append("\r\n"); - sbuf.append("\r\n"); + sbuf.append("\r\n"); return sbuf.toString().getBytes(getCharset()); } Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.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/pattern/NameAbbreviator.java?rev=1201395&r1=1201394&r2=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java Sun Nov 13 02:28:23 2011 @@ -164,7 +164,7 @@ public abstract class NameAbbreviator { * @param count maximum number of path elements to output. */ public MaxElementAbbreviator(final int count) { - this.count = count; + this.count = count < 1 ? 1 : count; } /** Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.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/pattern/SequenceNumberPatternConverter.java?rev=1201395&r1=1201394&r2=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java Sun Nov 13 02:28:23 2011 @@ -20,6 +20,8 @@ package org.apache.logging.log4j.core.pa import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.plugins.Plugin; +import java.util.concurrent.atomic.AtomicLong; + /** * Formats the event sequence number. @@ -27,6 +29,7 @@ import org.apache.logging.log4j.core.con @Plugin(name="SequenceNumberPatternConverter", type="Converter") @ConverterKeys({"sn", "sequenceNumber"}) public class SequenceNumberPatternConverter extends LogEventPatternConverter { + private static AtomicLong sequence = new AtomicLong(); /** * Singleton. */ @@ -55,6 +58,6 @@ public class SequenceNumberPatternConver * {@inheritDoc} */ public void format(final LogEvent event, final StringBuilder toAppendTo) { - toAppendTo.append("0"); + toAppendTo.append(Long.toString(sequence.incrementAndGet())); } } Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/UUIDPatternConverter.java (from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.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/pattern/UUIDPatternConverter.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/UUIDPatternConverter.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java&r1=1195339&r2=1201395&rev=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/UUIDPatternConverter.java Sun Nov 13 02:28:23 2011 @@ -17,27 +17,32 @@ package org.apache.logging.log4j.core.pattern; +import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.helpers.UUIDUtil; +import org.apache.logging.log4j.status.StatusLogger; + +import java.util.UUID; /** * Formats the event sequence number. */ -@Plugin(name="SequenceNumberPatternConverter", type="Converter") -@ConverterKeys({"sn", "sequenceNumber"}) -public class SequenceNumberPatternConverter extends LogEventPatternConverter { - /** - * Singleton. - */ - private static final SequenceNumberPatternConverter INSTANCE = - new SequenceNumberPatternConverter(); +@Plugin(name="UUIDPatternConverter", type="Converter") +@ConverterKeys({"u", "uuid"}) +public class UUIDPatternConverter extends LogEventPatternConverter { + + private final boolean isRandom; + + private static Logger logger = StatusLogger.getLogger(); /** * Private constructor. */ - private SequenceNumberPatternConverter() { - super("Sequence Number", "sn"); + private UUIDPatternConverter(boolean isRandom) { + super("u", "uuid"); + this.isRandom = isRandom; } /** @@ -46,15 +51,22 @@ public class SequenceNumberPatternConver * @param options options, currently ignored, may be null. * @return instance of SequencePatternConverter. */ - public static SequenceNumberPatternConverter newInstance( - final String[] options) { - return INSTANCE; + public static UUIDPatternConverter newInstance(final String[] options) { + if (options.length == 0) { + return new UUIDPatternConverter(false); + } + + if (options.length > 1 || (!options[0].equalsIgnoreCase("RANDOM") && !options[0].equalsIgnoreCase("Time"))) { + logger.error("UUID Pattern Converter only accepts a single option with the value \"RANDOM\" or \"TIME\""); + } + return new UUIDPatternConverter(options[0].equalsIgnoreCase("RANDOM")); } /** * {@inheritDoc} */ public void format(final LogEvent event, final StringBuilder toAppendTo) { - toAppendTo.append("0"); + UUID uuid = isRandom ? UUID.randomUUID() : UUIDUtil.getTimeBasedUUID(); + toAppendTo.append(uuid.toString()); } } Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/flume/UUIDTest.java URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/flume/UUIDTest.java?rev=1201395&r1=1201394&r2=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/flume/UUIDTest.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/flume/UUIDTest.java Sun Nov 13 02:28:23 2011 @@ -1,5 +1,6 @@ package org.apache.logging.log4j.core.appender.flume; +import org.apache.logging.log4j.core.helpers.UUIDUtil; import org.junit.Test; import java.util.UUID; Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java?rev=1201395&r1=1201394&r2=1201395&view=diff ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java (original) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java Sun Nov 13 02:28:23 2011 @@ -19,15 +19,16 @@ package org.apache.logging.log4j.core.la import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.ThreadContext; -import org.apache.logging.log4j.core.Appender; -import org.apache.logging.log4j.core.Lifecycle; +import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.BasicConfigurationFactory; import org.apache.logging.log4j.core.appender.FileAppender; import org.apache.logging.log4j.core.appender.FileManager; import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.apache.logging.log4j.core.impl.Log4jLogEvent; import org.apache.logging.log4j.core.util.Compare; +import org.apache.logging.log4j.message.SimpleMessage; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -35,6 +36,7 @@ import org.junit.Test; import java.io.FileOutputStream; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; /** * @@ -46,6 +48,7 @@ public class PatternLayoutTest { Logger root = ctx.getLogger(""); static String msgPattern = "%m%n"; + static final String regexPattern = "%replace{%logger %msg}{\\.}{/}"; static ConfigurationFactory cf = new BasicConfigurationFactory(); @BeforeClass @@ -132,4 +135,15 @@ public class PatternLayoutTest { appender.stop(); } + + @Test + public void testRegex() throws Exception { + LoggerContext ctx = (LoggerContext) LogManager.getContext(); + PatternLayout layout = PatternLayout.createLayout(regexPattern, ctx.getConfiguration(), + null, null); + LogEvent event = new Log4jLogEvent(this.getClass().getName(), null, "org.apache.logging.log4j.core.Logger", + Level.INFO, new SimpleMessage("Hello, world!"), null); + byte[] result = layout.format(event); + assertEquals("org/apache/logging/log4j/core/layout/PatternLayoutTest Hello, world!", new String(result)); + } } Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/NameAbbreviatorTest.java URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/NameAbbreviatorTest.java?rev=1201395&view=auto ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/NameAbbreviatorTest.java (added) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/NameAbbreviatorTest.java Sun Nov 13 02:28:23 2011 @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.pattern; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * + */ +public class NameAbbreviatorTest { + + @Test + public void testZero() { + String str = this.getClass().getName(); + NameAbbreviator a = NameAbbreviator.getAbbreviator("0"); + String result = a.abbreviate(str); + assertEquals("NameAbbreviatorTest", result); + } + + @Test + public void testNameAbbreviation() { + String str = this.getClass().getName(); + NameAbbreviator a = NameAbbreviator.getAbbreviator("1"); + String result = a.abbreviate(str); + assertEquals("NameAbbreviatorTest", result); + } + + @Test + public void testTwo() { + String str = this.getClass().getName(); + NameAbbreviator a = NameAbbreviator.getAbbreviator("2"); + String result = a.abbreviate(str); + assertEquals("pattern.NameAbbreviatorTest", result); + + } + + @Test + public void testShortName() { + String str = this.getClass().getName(); + NameAbbreviator a = NameAbbreviator.getAbbreviator("1."); + String result = a.abbreviate(str); + assertEquals("o.a.l.l.c.p.NameAbbreviatorTest", result); + + } + + @Test + public void testSkipNames() { + String str = this.getClass().getName(); + NameAbbreviator a = NameAbbreviator.getAbbreviator("1.1.~"); + String result = a.abbreviate(str); + assertEquals("o.a.~.~.~.~.NameAbbreviatorTest", result); + + } + + @Test + public void testZeroDot() { + String str = this.getClass().getName(); + NameAbbreviator a = NameAbbreviator.getAbbreviator("."); + String result = a.abbreviate(str); + assertEquals("......NameAbbreviatorTest", 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=1201395&r1=1201394&r2=1201395&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 Sun Nov 13 02:28:23 2011 @@ -81,6 +81,18 @@ + + + + + + + + + + + + Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/extending.xml URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/extending.xml?rev=1201395&view=auto ============================================================================== --- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/extending.xml (added) +++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/extending.xml Sun Nov 13 02:28:23 2011 @@ -0,0 +1,60 @@ + + + + + + Extending Log4j + Ralph Goers + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + \ 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=1201395&r1=1201394&r2=1201395&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 Sun Nov 13 02:28:23 2011 @@ -18,34 +18,730 @@ - Overview + Log4j Layouts Ralph Goers
+

+ Layouts are used by Appenders to format the LogEvent into a form that meets the needs of whoever will be + consuming the log events. In Log4j 1.x and Logback Layouts were expected to transform an event into a + String. In Log4j 2.0 Layouts return a byte array. This allows the result of the Layout to be useful in + many more types of Appenders. However, this means most Layouts need to be configured with a + Charset to + insure the byte array contains correct values. +

- + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Parameter NameTypeDescription
charsetStringThe character set to use when converting the HTML String to a byte array. The value must be + a valid Charset. + If not specified, the default system Charset will be used.
contentTypeStringThe value to assign to the Content-Type header. The default is "text/html".
locationInfobooleanIf true, the filename and line number will be included in the HTML output. The default value is + false.
titleStringA String that will appear as the HTML title.
HTML Layout Parameters
+

+ A flexible layout configurable with pattern string. The goal of this class is to format a LogEvent and + return the results. The format of the result depends on the conversion pattern. +

+

+ The conversion pattern is closely related to the conversion pattern of the printf function in C. + A conversion pattern is composed of literal text and format control expressions called + conversion specifiers. +

+

+ Note that any literal text may be included in the conversion pattern. +

+

+ Each conversion specifier starts with a percent sign (%) and is followed by optional format + modifiers and a conversion character. The conversion character specifies the type of + data, e.g. category, priority, date, thread name. The format modifiers control such things as field width, + padding, left and right justification. The following is a simple example. +

+

+ Let the conversion pattern be "%-5p [%t]: %m%n" and assume that the log4j environment was set to + use a PatternLayout. Then the statements +

+ Logger logger = LogManager.getLogger("MyLogger");
+ logger.debug("Message 1");
+ logger.warn("Message 2");
+ 
+ would yield the output +
+ DEBUG [main]: Message 1
+ WARN  [main]: Message 2
+ 
+

+

+ Note that there is no explicit separator between text and conversion specifiers. The pattern parser + knows when it has reached the end of a conversion specifier when it reads a conversion character. + In the example above the conversion specifier %-5p means the priority of the logging event should + be left justified to a width of five characters. +

+ + + + + + + + + + + + + + + + + + + + + + +
Parameter NameTypeDescription
charsetStringThe character set to use when converting the syslog String to a byte array. The String must be + a validCharset. + If not specified, the default system Charset will be used. +
patternString
replaceRegexReplacementAllows portions of the resulting String to be replaced. If configured, the replace element must + specify the regular expression to match and the substitution. This performs a function similar to + the RegexReplacement converter but applies to the whole message while the converter only + applies to the String its pattern generates. +
Pattern Layout Parameters
+

Patterns

+

+ The conversions that are provided with Log4j are: +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Coversion PatternDescription
+ c{precision}
+ logger{precision} +
+

+ Used to output the name of the logger that published the logging event. The logger conversion + specifier can be optionally followed byprecision specifier, which consists of a + decimal integer, or a pattern starting with a decimal integer. +

+

If a precision specifier is given and it is an integer value, then only the corresponding number + of right most components of the logger name will be printed. If the precision contains + other non-integer characters then the name will be abbreviated based on the pattern. If the + precision integer is less than one the right-most token will still be printed in full. + By default the logger name is printed in full. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Conversion PatternLogger NameResult
%c{1}org.apache.commons.FooFoo
%c{2}org.apache.commons.Foocommons.Foo
%c{1.}org.apache.commons.Fooo.a.c.Foo
%c{1.1.~.~}org.apache.commons.test.Fooo.a.~.~.Foo
%c{.}org.apache.commons.test.Foo....Foo
+
+ C{precision}
+ class{precision} +
+

+ Used to output the fully qualified class name of the caller issuing the logging request. + This conversion specifier can be optionally followed byprecision specifier, that + follows the same rules as the logger name converter. +

+
+ d{pattern}
+ date{pattern} +
+

+ Used to output the date of the logging event. The date conversion specifier may be + followed by a set of braces containing a date and time pattern strings + + SimpleDateFormat, + ABSOLUTE, + DATE + or + ISO8601 + and a set of braces containing a time zone id per + + java.util.TimeZone.getTimeZone. + For example,%d{HH:mm:ss,SSS},%d{dd MMM yyyy HH:mm:ss,SSS}, + %d{DATE} + or%d{HH:mm:ss}{GMT+0}. If no date format specifier is given then + ISO8601 format is assumed. +

+
+ F
+ file +
+ Used to output the file name where the logging request was issued. +
+ l
+ location +
+

+ Used to output location information of the caller which generated the logging event. +

+

+ The location information depends on the JVM implementation but usually consists of the fully + qualified name of the calling method followed by the callers source the file name and line + number between parentheses. +

+
+ L
+ line +
Used to output the line number from where the logging request + was issued. +
+ m
+ msg
+ message +
Used to output the application supplied message associated with the logging event. +
+ M
+ method +
Used to output the method name where the logging request was issued. +
+ marker + The name of the marker, if one is present.
+ n + +

+ Outputs the platform dependent line separator character or characters. +

+

This conversion character offers practically the same + performance as using non-portable line separator strings such as + "\n", or "\r\n". Thus, it is the preferred way of specifying a + line separator. +

+
+ p
+ level +
Used to output the level of the logging event.
+ r
+ relative +
Used to output the number of milliseconds elapsed since the JVM was started until the creation + of the logging event. +
+ replace{pattern}{regex}{substitution} + +

+ Replaces occurrences of 'regex', a regular expression, with its replacement 'substitution' in the + string resulting from evaluation of the pattern. For example, "%replace(%msg}{\s}{}" will remove + all spaces contained in the event message. +

+

+ The pattern can be arbitrarily complex and in particular can contain multiple conversion keywords. + For instance, "%replace{%logger %msg}{\.}{/}" will replace all dots in the logger or the message of + the event with a forward slash. +

+
+ t
+ thread +
Used to output the name of the thread that generated the logging event.
+ x
+ NDC +
Used to output the Thread Context Stack (also known as the Nested Diagnostic Context or NDC) + associated with the thread that generated the logging event. +
+ X{key}
+ MDC{key} +
+

Used to output the Thread Context Map (also known as the Mapped Diagnostic Context or MDC) + associated with the thread that generated the logging event. The + X + conversion character can be followed by the key for the + map placed between braces, as in + %X{clientNumber} + where + clientNumber + is the key. The value in the MDC + corresponding to the key will be output. If no additional sub-option + is specified, then the entire contents of the MDC key value pair set + is output using a format {{key1,val1},{key2,val2}} +

+

See the + ThreadContext + class for more details. +

+
+ ex{depth}
+ exception{depth}
+ throwable{depth} +
+

Used to output the Throwable trace that has been bound to the LoggingEvent, by + default this will output the full trace as one would normally find by a call to + Throwable.printStackTrace(). + The throwable conversion word can be followed by an option in the form + %throwable{short} + which will only output the first line of the Throwable or %throwable{n} where + the first n lines of the stacktrace will be printed. +

+
+ rEx{depth}
+ rException{depth}
+ rThrowable{depth} +
+

+ The same as the %throwable conversion word but the stack trace is printed starting with the + first exception that was thrown followed by each subsequent wrapping exception. +

+
+ xEx{depth}
+ xException{depth}
+ xThrowable{depth} +
+

+ The same as the %throwable conversion word but also includes class packaging information. +

+

+ At the end of each stack element of the exception, a string containing the name of the jar file + that contains the class or the directory the class is located in and the "Implementation-Version" + as found in that jar's manifest will be added. If the information is uncertain, then the class + packaging data will be preceded by a tilde, i.e. the '~' character. +

+
+ sn
+ sequenceNumber +
Includes a sequence number that will be incremented in every event. The counter is a + static variable so will only be unique within applications that share the same converter Class + object.
+ u{"RANDOM" | "TIME"}
+ uuid +
Includes either a random or a time-based UUID. The time-based UUID is a Type 1 UUID that can + generate up to 10,000 unique ids per millisecond, will use the MAC address of each host, and to + try to insure uniqueness across multiple JVMs and/or ClassLoaders on the same host a + random number between 0 and 16,384 will be associated with each instance of the UUID generator + Class and included in each time-based UUID generated. Because time-based UUIDs contain + the MAC address and timestamp they should be used with care as they can cause a security + vulnerability. +
+ % + The sequence %% outputs a single percent sign. +
+

By default the relevant information is output as is. However, + with the aid of format modifiers it is possible to change the + minimum field width, the maximum field width and justification. +

+

The optional format modifier is placed between the percent sign + and the conversion character. +

+

The first optional format modifier is the + left justification + flag + + which is just the minus (-) character. Then comes the + optional + minimum field width + modifier. This is a decimal + constant that represents the minimum number of characters to + output. If the data item requires fewer characters, it is padded on + either the left or the right until the minimum width is + reached. The default is to pad on the left (right justify) but you + can specify right padding with the left justification flag. The + padding character is space. If the data item is larger than the + minimum field width, the field is expanded to accommodate the + data. The value is never truncated. +

+

This behavior can be changed using the + maximum field + width + + modifier which is designated by a period followed by a + decimal constant. If the data item is longer than the maximum + field, then the extra characters are removed from the + beginning + of the data item and not from the end. For + example, it the maximum field width is eight and the data item is + ten characters long, then the first two characters of the data item + are dropped. This behavior deviates from the printf function in C + where truncation is done from the end. +

+

Below are various format modifier examples for the category + conversion specifier. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Format modifierleft justifyminimum widthmaximum widthcomment
%20cfalse20noneLeft pad with spaces if the category name is less than 20 + characters long. +
%-20ctrue20 + noneRight pad with + spaces if the category name is less than 20 characters long. +
%.30cNAnone30Truncate from the beginning if the category name is longer than 30 + characters. +
%20.30cfalse2030Left pad with spaces if the category name is shorter than 20 + characters. However, if category name is longer than 30 characters, + then truncate from the beginning. +
%-20.30ctrue2030Right pad with spaces if the category name is shorter than 20 + characters. However, if category name is longer than 30 characters, + then truncate from the beginning. +
Pattern Converters
- +

+ As the name implies, the RFC5424Layout formats LogEvents in accordance with + 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. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Parameter NameTypeDescription
appNameStringThe value to use as the APP-NAME in the RFC 5424 syslog record.
charsetStringThe character set to use when converting the syslog String to a byte array. The String must be + a valid Charset. + If not specified, the default system Charset will be used.
enterpriseNumberintegerThe IANA enterprise number as described in + RFC 5424
facilityStringThe facility is used to try to classify the message. The facility option must be set to one of + "KERN", "USER", "MAIL", "DAEMON", "AUTH", "SYSLOG", "LPR", "NEWS", "UUCP", "CRON", "AUTHPRIV", + "FTP", "NTP", "AUDIT", "ALERT", "CLOCK", "LOCAL0", "LOCAL1", "LOCAL2", "LOCAL3", "LOCAL4", "LOCAL5", + "LOCAL6", or "LOCAL7". These values may be specified as upper or lower case characters.
formatStringIf set to "RFC5424" the data will be formatted in accordance with RFC 5424. Otherwise, it will + be formatted as a BSD Syslog record. Note that although BSD Syslog records are required to be + 1024 bytes or shorter the SyslogLayout does not truncate them. The RFC5424Layout also does not + truncate records since the receiver must accept records of up to 2048 bytes and may accept records + that are longer.
idStringThe default structured data id to use when formatting according to RFC 5424. If the LogEvent contains + a StructuredDataMessage the id from the Message will be used instead of this value.
immediateFlushbooleanWhen set to true, each write will be followed by a flush. This will guarantee the data is written + to disk but could impact performance.
includeMDCbooleanIndicates whether data from the ThreadContextMap will be included in the RFC 5424 Syslog record. + Defaults to true.
mdcExcludesStringA comma separated list of mdc keys that should be excluded from the LogEvent. This is mutually + exclusive with the mdcIncludes attribute. This attribute only applies to RFC 5424 syslog records.
mdcIncludesStringA comma separated list of mdc keys that should be included in the FlumeEvent. Any keys in the MDC + not found in the list will be excluded. This option is mutually exclusive with the mdcExcludes + attribute. This attribute only applies to RFC 5424 syslog records.
mdcRequiredStringA comma separated list of mdc keys that must be present in the MDC. If a key is not present a + LoggingException will be thrown. This attribute only applies to RFC 5424 syslog records.
mdcPrefixStringA string that should be prepended to each MDC key in order to distinguish it from event attributes. + The default string is "mdc:". This attribute only applies to RFC 5424 syslog records.
messageIdStringThe default value to be used in the MSGID field of RFC 5424 syslog records.
newLinebooleanIf true, a newline will be appended to the end of the syslog record. The default is false.
RFC5424Layout Parameters
+

+ The SerializedLayout simply serializes the LogEvent into a byte array. This is useful when + sending messages via JMS or via a Socket connection. The SerializedLayout accepts no parameters. +

- +

+ The SyslogLayout formats the LogEvent as BSD Syslog records matching the same format used by + Log4j 1.2. +

+ + + + + + + + + + + + + + + + + + + + + + +
Parameter NameTypeDescription
charsetStringThe character set to use when converting the syslog String to a byte array. The String must be + a valid Charset. + If not specified, the default system Charset will be used.
facilityStringThe facility is used to try to classify the message. The facility option must be set to one of + "KERN", "USER", "MAIL", "DAEMON", "AUTH", "SYSLOG", "LPR", "NEWS", "UUCP", "CRON", "AUTHPRIV", + "FTP", "NTP", "AUDIT", "ALERT", "CLOCK", "LOCAL0", "LOCAL1", "LOCAL2", "LOCAL3", "LOCAL4", "LOCAL5", + "LOCAL6", or "LOCAL7". These values may be specified as upper or lower case characters.
newLinebooleanIf true, a newline will be appended to the end of the syslog record. The default is false.
SyslogLayout Parameters
- +

+ The output of the XMLLayout consists of a series of log4j:event + elements as defined in thelog4j.dtd. If configured to do so it will + output a complete well-formed XML file. The output is designed to be + included as an + external entity + in a separate file to form + a correct XML file. +

+

For example, if abc is the name of the file where + the XMLLayout ouput goes, then a well-formed XML file would be: +

+
+            <?xml version="1.0" ?>
+            *
+            <!DOCTYPE log4j:eventSet SYSTEM "log4j.dtd" [<!ENTITY data SYSTEM "abc">]>
+            *
+            <log4j:eventSet version="2.0" xmlns:log4j="http://logging.apache.org/log4j/">
+              &data;
+            </log4j:eventSet>
+          
+

+ This approach enforces the independence of the XMLLayout and the appender where it is embedded. +

+

+ The version attribute helps components to correctly intrepret output generated by XMLLayout. + The value of this attribute should be "2.0". +

+

+ Appenders using this layout should have their encoding set to UTF-8 or UTF-16, otherwise events containing + non ASCII characters could result in corrupted log files. +