Syntax for a Pattern Layout

Note: A pattern layout is configured by using the <layout> and </layout> elements. Any <appender> element attributes and subelements in the syntax are present to show the context for the pattern layout elements.

Syntax

XML Configuration
<appender class="AppenderName" name="appender-reference-name">
<layout>
<param name="Header" value="header-text"/>
<param name="HeaderPattern" value="conversion-pattern"/>
<param name="ConversionPattern" value="conversion-pattern"/>
<param name="Footer" value="footer-text"/>
<param name="FooterPattern" value="conversion-pattern"/>
<param name="XmlEscape" value="TRUE | FALSE"/>
</layout>
</appender>

Syntax Description

class= "AppenderName "name="appender-reference-name"
specifies the name of the appender reference that is to be used as an appender-ref for a logger.
See For appender class names, see Appender Reference.
name="Header" value="header-text"
specifies the header text that the appender uses when it starts a new log.
Valid in XML configuration files for the File, RollingFile, and Console appender classes.
name="HeaderPattern" value="conversion-pattern"
specifies the pattern layout that is used to identify, order, and format information in a header. A conversion pattern consists of optional literal text and optional format-control directives, which are called conversion specifiers. Each conversion specifier begins with a percent sign (%) and is followed by optional format modifiers and one or more instances of the S conversion character or the d conversion character. The format modifiers control field width, padding, and left and right justification.
Here is the syntax for a header pattern:
[literal-text] %[format-modifier-1] conversion-character-1
[… [literal-text] %[format-modifier-n] conversion-character-n] />
Valid in XML configuration files for the File, RollingFile, and Console appender classes.
Restriction The header pattern is limited to the S and d conversion characters in a logging configuration file.
Interaction The Header parameter header-text takes precedence over the HeaderPattern conversion-pattern parameter.
Tips The specification of format modifiers is optional.
There is no explicit separator between literal text and the conversion specifier. The pattern parser recognizes the end of a conversion specifier when it detects the S or d conversion character.
See d Conversion Character
S Conversion Character
Format Modifiers
Example
<param name="HeaderPattern" value="%d %S{os_name} %S{jobid} %S{host_name} 
       %S{user_name}"/>
name="ConversionPattern" value="conversion-pattern"
specifies the pattern layout that is used to identify, order, and format information in the log event. A conversion pattern consists of literal text and format-control directives called conversion specifiers. Each conversion specifier begins with a percent sign (%) and is followed by optional format modifiers and a conversion character. The conversion character specifies the type of data (for example, category, priority, date, and thread name). The format modifiers control field width, padding, and left and right justification.
Here is the syntax for a conversion pattern:
[literal-text] %[format-modifier-1] conversion-character-1
[… [literal-text] %[format-modifier-n] conversion-character-n] />
Valid in XML configuration files for any appender class.
Default None. The log event produces an empty string if a conversion pattern is not specified.
Restrictions Conversion specifiers are case sensitive.
Do not use these problematic characters, known as variants, in pattern layouts in EBCDIC encoding environments: ! # $ @ \ []^`{}|~ \n. \n represents the use of the New Line (or Enter) key
These characters are problematic because they might occupy different code positions in various encodings that are supported by SAS. For example, the EBCDIC code point location 5A (hexadecimal) represents the exclamation point (!) in U.S. English and the right bracket ( ] ) in Spanish.
Tips The specification of format modifiers is optional.
There is no explicit separator between literal text and a conversion specifier. The pattern parser recognizes the end of a conversion specifier when it detects a conversion character.
See S Conversion Character
Format Modifiers
For more information about variant characters, see the SAS National Language Support (NLS): Reference Guide.
Example <param name="ConversionPattern" value="%d; %-5p; %t; %c; (%F:%L); %m"/>
name="Footer" value="footer-text"
specifies the footer text that the appender uses when it ends a log.
Valid in XML configuration files for the File, RollingFile, and Console appender classes.
name="FooterPattern" value="conversion-pattern"
specifies the pattern layout that is used to identify, order, and format information in a footer. A conversion pattern consists of optional literal text and optional format-control directives, which are called conversion specifiers. Each conversion specifier begins with a percent sign (%) and is followed by optional format modifiers and one or more instances of the S or d conversion characters. The format modifiers control field width, padding, and left and right justification.
Here is the syntax for a footer pattern:
[literal-text] %[format-modifier-1] conversion-character-1
[… [literal-text] %[format-modifier-n] conversion-character-n] />
Valid in XML configuration files for the File, RollingFile, and Console appender classes.
Restriction The footer pattern is limited to the S and d conversion characters in a logging configuration file.
Interaction The Footer parameter footer-text takes precedence over the FooterPattern conversion-pattern parameter.
Tip There is no explicit separator between literal text and a conversion specifier. The pattern parser recognizes the end of a conversion specifier when it detects a conversion character.
See d Conversion CharacterS Conversion Character
Format Modifiers
Example <param name="FooterPattern" value="%d %S{host_name}"/>
name="XmlEscape" value="TRUE | FALSE"
specifies whether certain characters that can be specified in the m, x, X, and S conversion specifiers are converted to their entity representations.
TRUE
specifies that the following characters are converted when they are used in the m, x, X, and S conversion specifiers:
  • "<" is converted to "&lt;"
  • ">" is converted to "&gt;"
  • "" (double quotation marks) is converted to "&quot;"
  • "'" (single quotation mark) is converted to "&apos;"
  • "&" is converted to "&amp;"
FALSE
specifies that no character conversion to entity representations is performed.

Example: 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{2} (%F:%L) %m"/>  
</layout> 
                                                                      
Here is an explanation:
Example of a Layout Pattern
Pattern Layout
Explanation
Example
%d
reports the date of the log event and formats the date using the default format, ISO8601.
2011-06-25 10:24:22,234
%-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
%t
reports the identifier of the thread that generated the log event.
0000000
%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;.
(%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)
The parentheses ( () ) and colon (:) are literal text.
%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.