Share via


SimpleFormatter.Format(LogRecord) Method

Definition

Format the given LogRecord.

[Android.Runtime.Register("format", "(Ljava/util/logging/LogRecord;)Ljava/lang/String;", "GetFormat_Ljava_util_logging_LogRecord_Handler")]
public override string? Format (Java.Util.Logging.LogRecord? record);
[<Android.Runtime.Register("format", "(Ljava/util/logging/LogRecord;)Ljava/lang/String;", "GetFormat_Ljava_util_logging_LogRecord_Handler")>]
override this.Format : Java.Util.Logging.LogRecord -> string

Parameters

record
LogRecord

the log record to be formatted.

Returns

a formatted log record

Attributes

Remarks

Format the given LogRecord.

The formatting can be customized by specifying the format string in the <c>java.util.logging.SimpleFormatter.format</c> property. The given LogRecord will be formatted as if by calling:

{@link String#format String.format}(format, date, source, logger, level, message, thrown);

where the arguments are:<br> <ol> <li>format - the java.util.Formatter java.util.Formatter format string specified in the java.util.logging.SimpleFormatter.format property or the default format.</li> <li>date - a Date object representing LogRecord#getMillis event time of the log record.</li> <li>source - a string representing the caller, if available; otherwise, the logger's name.</li> <li>logger - the logger's name.</li> <li>level - the Level#getLocalizedName log level.</li> <li>message - the formatted log message returned from the Formatter#formatMessage(LogRecord) method. It uses java.text.MessageFormat java.text formatting and does not use the java.util.Formatter format argument.</li> <li>thrown - a string representing the LogRecord#getThrown throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.</li> </ol>

Some example formats:<br> <ul> <li> java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"

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

WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011]

</li> <li> 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 (1$) and the source (2$); the second line includes the log level (4$) and the log message (5$) followed with the throwable and its backtrace (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)

</li> <li> 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

</li> </ul>

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.

Java documentation for java.util.logging.SimpleFormatter.format(java.util.logging.LogRecord).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to