自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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 |"]]