SimpleFormatter.Format(LogRecord) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
格式化給定的 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
參數
- record
- LogRecord
日誌記錄格式化。
傳回
格式化日誌記錄
- 屬性
備註
格式化給定的 LogRecord。
格式可透過 c<java.util.logging.SimpleFormatter.format>/c< 屬性中指定格式字>串來自訂。 給出 LogRecord 的格式將如同呼叫:
{@link String#format String.format}(format, date, source, logger, level, message, thrown);
其中參數為:<br><ol><li>format - java.util.Formatter java.util.Formatter 屬性中指定的java.util.logging.SimpleFormatter.format格式字串或預設格式。</li><li>date - Date 代表LogRecord#getMillis事件時間的物件。</li><li>source - 代表呼叫者的字串(若有);否則為記錄者名稱。</李><里>logger——伐木工的名字。</li><li>level - Level#getLocalizedName 日誌層級。</li><li>message - 方法回傳Formatter#formatMessage(LogRecord)的格式化日誌訊息。 它使用格式java.text.MessageFormat java.text化,且不使用論證。java.util.Formatter format</li><li>thrown - 代表與日誌記錄及其以換行字元開頭的回溯相關聯的 LogRecord#getThrown 拋接檔的字串(若有的話);否則為空字串。</li></ol>
一些範例格式:<br><ul><li>java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"
這會印出一行,對數等級4$()、對數訊息(5$)和時間戳1$()放在方括號內。
WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011]
</李><莉>java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"
此系統會列印兩行,第一行包含時間戳記(1$)和來源(2$);第二行包含日誌層級(4$)和日誌訊息(5$),接著是拋送檔及其回溯6$(如果有的話):
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)
</李><莉>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"
此工具會列印兩行類似上述範例但日期/時間格式不同,且不會列印可投擲物及其回溯:
Mar 22, 2011 1:11:31 PM MyClass fatal
SEVERE: several message with an exception
</li></ul>
此方法也可以在子類別中被覆寫。 建議使用 Formatter#formatMessage 便利性方法來本地化並格式化訊息欄位。
Java 文件 java.util.logging.SimpleFormatter.format(java.util.logging.LogRecord)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。