Conversion character reference

Use the conversion characters listed in the following table to specify the formatting of logging category conversion patterns in file log4j-2.xml. For more information on conversion patterns, refer to the following Apache documentation:

Character

Description

%%

Writes the percent sign to output.

%c

Name of the logging category (the logger name).

%C

Name of the Java class. Because the PolicyCenter logging API is a wrapper around log4j, %C returns the class name of the logger. If you want class names in your log messages, include them specifically in the message rather than by using %C in the conversion pattern.

%d

Date and time. Acceptable formats include:

  • %d{ISO8601}
  • %d{DATE}
  • %d{ABSOLUTE}
  • %d{HH:mm:ss,SSS}
  • %d{dd MMM yyyy HH:mm:ss,SSS}
  • ...

PolicyCenter uses %d{ISO8601} by default.

%F

Name of the Java source file. Because the PolicyCenter logging API is a wrapper around log4j, %F returns a file name for the PolicyCenter logging API. If you want file names in your log messages, include them specifically in the message rather than by using %F in the conversion pattern.

%l

Abbreviated format for %F%L%C%M. This outputs the Java source file name, line number, class name and method name. Because the PolicyCenter logging API is a wrapper around log4j, the information returned is for the PolicyCenter logging API. If you want information such as class and method names in your log messages, include them specifically in the message rather than by using %l in the conversion pattern.

%L

Line number in Java source. Because the PolicyCenter logging API is a wrapper around log4j, %L returns a line number from the PolicyCenter logging API. If you want line numbers in your log messages, include them specifically in the message rather than by using %L in the conversion pattern.

%m

The log message.

%M

Name of the Java method. Because the PolicyCenter logging API is a wrapper around log4j, %M returns info string. If you want method names in your log messages, include them specifically in the message rather than by using %M in the conversion pattern.

%n

New line character of the operating system. This is preferable to entering \n or \r\n as it works across platforms.

%notEmpty Outputs the result of evaluating the pattern if and only if all variables in the pattern are not empty. In the context of logging markers, this is:
  • %notEmpty{< %marker >}

%p

Priority of the message. Typically, either FATAL, ERROR, WARN, INFO or DEBUG. You can also create custom priorities in your own code.

%r

Number of milliseconds since the program started running.

%t

Name of the current thread.

%throwable

Include a throwable logged with the message. Available format is:

  • %throwable – Display the whole stack trace.
  • %throwable{n} – Limit display of stack trace to n lines.
  • %throwable{none} – Equivalent of %throwable{0}. No stack trace.
  • %throwable{short} – Equivalent of %throwable{1}. Only first line of stack trace.

%X

The nested diagnostic context. You can use this to include server and user information in logging messages. Specify a key in the following format to retrieve that information from the nested diagnostic context: %X{key}. The following keys are available:

  • server
  • user
  • userID
  • userName
  • traceabilityID

For example, to include the server name, add %X{server}. For example, to include the server name, add %X{server}.

There are three options for logging user information in logging patterns:

user – prints the numeric opaque ID for the user

userID – a unique user ID string, such as "aapplegate"

userName – a real name, such as "Andy Applegate"

For any of these, specify the minimum and the maximum size of the field. For example: %-16.16X{userName}.

If the actual value is shorter than the minimum field size, the user identifier gets padded with spaces on the right. If the actual value is longer than the maximum size of the field, the user identifier gets truncated from the left.

The user key lists a sequence number assigned to the user by the server and is not very informative. To include user login ID information, instead use the userID key.

See also