Home » openjdk-7 » java » util » logging » [javadoc | source]
java.util.logging
public class: SimpleFormatter [javadoc | source]
java.lang.Object
   java.util.logging.Formatter
      java.util.logging.SimpleFormatter
Print a brief summary of the {@code LogRecord} in a human readable format. The summary will typically be 1 or 2 lines.

Configuration: The {@code SimpleFormatter} is initialized with the format string specified in the {@code java.util.logging.SimpleFormatter.format} property to {@linkplain #format format} the log messages. This property can be defined in the {@linkplain LogManager#getProperty logging properties} configuration file or as a system property. If this property is set in both the logging properties and system properties, the format string specified in the system property will be used. If this property is not defined or the given format string is {@linkplain java.util.IllegalFormatException illegal}, the default format is implementation-specific.

Method from java.util.logging.SimpleFormatter Summary:
format
Methods from java.util.logging.Formatter:
format,   formatMessage,   getHead,   getTail
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.util.logging.SimpleFormatter Detail:
 public synchronized String format(LogRecord record) 
    Format the given LogRecord.

    The formatting can be customized by specifying the format string in the {@code java.util.logging.SimpleFormatter.format} property. The given {@code LogRecord} will be formatted as if by calling:

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

    Some example formats:

    • {@code java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"}

      This prints 1 line with the log level ({@code 4$}), the log message ({@code 5$}) and the timestamp ({@code 1$}) in a square bracket.

          WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011]
          
    • {@code java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"}

      This prints 2 lines where the first line includes the timestamp ({@code 1$}) and the source ({@code 2$}); the second line includes the log level ({@code 4$}) and the log message ({@code 5$}) followed with the throwable and its backtrace ({@code 6$}), if any:

          Tue Mar 22 13:11:31 PDT 2011 MyClass fatal
          SEVERE: several message with an exception
          java.lang.IllegalArgumentException: invalid argument
                  at MyClass.mash(MyClass.java:9)
                  at MyClass.crunch(MyClass.java:6)
                  at MyClass.main(MyClass.java:3)
          
    • {@code java.util.logging.SimpleFormatter.format="%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%n"}

      This prints 2 lines similar to the example above with a different date/time formatting and does not print the throwable and its backtrace:

          Mar 22, 2011 1:11:31 PM MyClass fatal
          SEVERE: several message with an exception
          

    This method can also be overridden in a subclass. It is recommended to use the Formatter#formatMessage convenience method to localize and format the message field.