Previous Page | Next Page

Pattern Layout

Examples


Examples of Format Modifiers

Here are examples of format modifiers that are used with the c conversion character. The c conversion character reports the name of the logger.

Format Modifier Left Justification Minimum Width Maximum Width Explanation
%20c no 20 none If the data item occupies fewer than 20 characters, pad to the left, using spaces.
%-20c yes 20 none If the data item occupies fewer than 20 characters, pad to the right, using spaces.
%.30c not applicable none 30 If the data item exceeds 30 characters, left-truncate the data item.
%20.30c no 20 30 If the data item occupies fewer than 20 characters, pad to the left, using spaces. If the data item exceeds 30 characters, left-truncate the data item.
%-20.30c yes 20 30 If the data item occupies fewer than 20 characters, pad to the right, using spaces. If the data item exceeds 30 characters, left-truncate the data item.


Example of a Pattern Layout

Here is an excerpt of an XML file that contains a pattern layout:

<layout>
   <param name="ConversionPattern"  value="%d %-5p %t %c (%F:%L) %m"/>  
</layout> 
                                                                      

Here is an explanation:

Pattern Layout Explanation Example
%d reports the date of the log event and formats the date using the default format, ISO8601. 2008-06-25 10:24:22,234;

Note:   The semicolon (;) is literal text.  [cautionend]

%-5p reports the level of the log event and left-justifies the level in output. If the level occupies fewer than five characters, the level is padded on the right. WARN ;

Note:   The semicolon (;) is literal text.  [cautionend]

%t reports the identifier of the thread that generated the log event. 3;

Note:   The semicolon (;) is literal text.  [cautionend]

%c{2} reports the name of the logger that generated the log event. The precision specifier limits the logger name to two subfields, causing left-truncation. The full logger name is Log4SAS.Appender.IOMCallContext. The formatted output is Appender.IOMCallContext;.

Note:   The semicolon (;) is literal text.  [cautionend]

(%F:%L) reports the filename and the line number in the application that generated the log event. The parentheses and colon are literal text that was specified in the conversion pattern. (ynl4sas.c:149);

Note:   The parentheses ( () ), colon (:), and semicolon (;) are literal text.  [cautionend]

%m reports the message that is supplied by the application and that is associated with the log event. Numeric maximum was larger than 8, am setting to 8.


Example of a Formatted Log Event

Here is an example of a formatted log event that is delivered to the appropriate output device:

Date Level Thread ID Logger Filename/Line Number Message
20008-06-25 10:24:22,234; WARN; 3; Appender.IOMCallContext; (ynl4.sas.c:149); Numeric maximum was larger than 8, am setting to 8.

Here is another view of the formatted log event as output:

2008-06-25-10:24:22,234; WARN; 3; Appender.IOMCallContext; (yn14.sas.c:149); 
                            Numeric maximum was larger than 8, am setting to 8.

Previous Page | Next Page | Top of Page