自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
LogUtil
public
class
LogUtil
extends Object
java.lang.Object
|
↳ |
com.android.tradefed.log.LogUtil
|
記錄公用程式類別。適用於需要覆寫 Log
中的靜態方法的程式碼
摘要
公用方法 |
static
String
|
getLogFormatString(Log.LogLevel logLevel, String tag, String message)
建立格式字串,類似裝置上的「threadtime」記錄格式。
|
static
void
|
printLog(Log.LogLevel logLevel, String tag, String message)
當需要列印記錄訊息時傳送。
|
公用方法
public static String getLogFormatString (Log.LogLevel logLevel,
String tag,
String message)
建立格式字串,類似於裝置上的「threadtime」記錄格式。這項功能特別實用,因為它包含日期和月份 (可用於區分長時間執行的 TF 例項),並使用 24 小時制時間,以便區分上午和晚上。
參數 |
logLevel |
Log.LogLevel |
tag |
String |
message |
String |
printLog
public static void printLog (Log.LogLevel logLevel,
String tag,
String message)
當需要列印記錄訊息時,系統會傳送這項事件。此實作會在所有情況下將訊息列印至標準輸出。
參數 |
logLevel |
Log.LogLevel :代表訊息優先度的 LogLevel 列舉。 |
tag |
String :與訊息相關聯的標記。 |
message |
String :要顯示的訊息。 |
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# LogUtil\n=======\n\n\n`\npublic\n\n\nclass\nLogUtil\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|----------------------------------|\n| java.lang.Object ||\n| ↳ | com.android.tradefed.log.LogUtil |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA logging utility class. Useful for code that needs to override static methods from [Log](../../../../../../reference/tradefed/com/android/tradefed/log/Log.html)\n\nSummary\n-------\n\n| ### Nested classes ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` class` | [LogUtil.CLog](../../../../../../reference/tradefed/com/android/tradefed/log/LogUtil.CLog.html) A shim class for [Log](../../../../../../reference/tradefed/com/android/tradefed/log/Log.html) that automatically uses the simple classname of the caller as the log tag |\n\n| ### Public methods ||\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static String` | ` `[getLogFormatString](../../../../../../reference/tradefed/com/android/tradefed/log/LogUtil.html#getLogFormatString(com.android.ddmlib.Log.LogLevel,%20java.lang.String,%20java.lang.String))`(Log.LogLevel logLevel, String tag, String message) ` Creates a format string that is similar to the \"threadtime\" log format on the device. |\n| ` static void` | ` `[printLog](../../../../../../reference/tradefed/com/android/tradefed/log/LogUtil.html#printLog(com.android.ddmlib.Log.LogLevel,%20java.lang.String,%20java.lang.String))`(Log.LogLevel logLevel, String tag, String message) ` Sent when a log message needs to be printed. |\n\nPublic methods\n--------------\n\n### getLogFormatString\n\n```\npublic static String getLogFormatString (Log.LogLevel logLevel, \n String tag, \n String message)\n```\n\nCreates a format string that is similar to the \"threadtime\" log format on the device. This\nis specifically useful because it includes the day and month (to differentiate times for\nlong-running TF instances), and also uses 24-hour time to disambiguate morning from evening.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|-----------------------|\n| `logLevel` | `Log.LogLevel` \u003cbr /\u003e |\n| `tag` | `String` \u003cbr /\u003e |\n| `message` | `String` \u003cbr /\u003e |\n\n| Returns ||\n|----------|--------|\n| `String` | \u003cbr /\u003e |\n\n**See also:**\n\n- [Log.getLogFormatString(LogLevel, String, String)](../../../../../../reference/tradefed/com/android/tradefed/log/Log.html#getLogFormatString(com.android.tradefed.log.Log.LogLevel,%20java.lang.String,%20java.lang.String)) \n\n### printLog\n\n```\npublic static void printLog (Log.LogLevel logLevel, \n String tag, \n String message)\n```\n\nSent when a log message needs to be printed. This implementation prints the message to\nstdout in all cases.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `logLevel` | `Log.LogLevel`: The [LogLevel](../../../../../../reference/tradefed/com/android/ddmlib/Log.LogLevel.html) enum representing the priority of the message. \u003cbr /\u003e |\n| `tag` | `String`: The tag associated with the message. \u003cbr /\u003e |\n| `message` | `String`: The message to display. \u003cbr /\u003e |"]]