Question

I imagine the answer may be different depending on the handler used, but let's say the ConsoleHandler is used and the default SimpleFormatter is used. What's the number, type, and possibly meaning/semantics of each of the parameters passed to the SimpleFormatter.format()?

I found this string in another SO question:

"%1\$tY-%1\$tm-%1\$td %1\$tH:%1\$tM:%1\$tS.%1\$tL %4\$s %2\$s %5\$s%6\$s%n"

(backslashes added for Groovy)

Notice the missing %3, so what is that argument? And is there a %7, %8, etc... and what are they?

I figured %1 is the current time and %4 is the log level and a couple others... I'm looking for the full list of arguments and their meaning/value.

Was it helpful?

Solution

From http://docs.oracle.com/javase/7/docs/api/java/util/logging/SimpleFormatter.html

where the arguments are:
   1 format - the java.util.Formatter format string specified in the java.util.logging.SimpleFormatter.format property or the default format.
   2 date - a Date object representing event time of the log record.
   3 source - a string representing the caller, if available; otherwise, the logger's name.
   4 logger - the logger's name.
   5 level - the log level.
   6 message - the formatted log message returned from the Formatter.formatMessage(LogRecord) method. It uses java.text formatting and does not use the java.util.Formatter format argument.
   7 thrown - a string representing the throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.

Since the first argument is the format string, the rest of the arguments start at index 1 (with the date first):

in the format string:
   1 date - a Date object representing event time of the log record.
   2 source - a string representing the caller, if available; otherwise, the logger's name.
   3 logger - the logger's name.
   4 level - the log level.
   5 message - the formatted log message returned from the Formatter.formatMessage(LogRecord) method. It uses java.text formatting and does not use the java.util.Formatter format argument.
   6 thrown - a string representing the throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.

(I cannot believe I couldn't find this in my initial search before posting to SO :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top