Most visited

Recently visited

Added in API level 1

Log

public final class Log
extends Object

java.lang.Object
   ↳ android.util.Log


用于发送日志输出的API。

通常,使用Log.v()Log.d()Log.i()Log.w()和Log.e()方法。

按照冗长的顺序排列,从最少到最多是ERROR,WARN,INFO,DEBUG,VERBOSE。 除了在开发期间,绝不应该将Verbose编译为应用程序。 调试日志被编译但在运行时剥离。 始终保留错误,警告和信息日志。

提示:一个好习惯是在你的课堂上声明一个 TAG常量:

private static final String TAG = "MyActivity";
and use that in subsequent calls to the log methods.

提示:当你拨打电话时,请不要忘记

Log.v(TAG, "index=" + i);
that when you're building the string to pass into Log.d, the compiler uses a StringBuilder and at least three allocations occur: the StringBuilder itself, the buffer, and the String object. Realistically, there is also another buffer allocation and copy, and even more pressure on the gc. That means that if your log message is filtered out, you might be doing significant work and incurring significant overhead.

Summary

Constants

int ASSERT

println方法的优先级常量。

int DEBUG

println方法的优先级常量; 使用Log.d.

int ERROR

println方法的优先级常量; 使用Log.e.

int INFO

println方法的优先级常量; 使用Log.i.

int VERBOSE

println方法的优先级常量; 使用Log.v.

int WARN

println方法的优先级常量; 使用Log.w.

Public methods

static int d(String tag, String msg, Throwable tr)

发送 DEBUG日志消息并记录异常。

static int d(String tag, String msg)

发送 DEBUG日志消息。

static int e(String tag, String msg)

发送 ERROR日志消息。

static int e(String tag, String msg, Throwable tr)

发送 ERROR日志消息并记录异常。

static String getStackTraceString(Throwable tr)

Handy函数从Throwable获取可记录的堆栈跟踪

static int i(String tag, String msg, Throwable tr)

发送 INFO日志消息并记录异常。

static int i(String tag, String msg)

发送 INFO日志消息。

static boolean isLoggable(String tag, int level)

检查指定标记的日志是否可以在指定级别登录。

static int println(int priority, String tag, String msg)

低级日志记录调用。

static int v(String tag, String msg)

发送 VERBOSE日志消息。

static int v(String tag, String msg, Throwable tr)

发送 VERBOSE日志消息并记录异常。

static int w(String tag, Throwable tr)
static int w(String tag, String msg, Throwable tr)

发送 WARN日志消息并记录异常。

static int w(String tag, String msg)

发送 WARN日志消息。

static int wtf(String tag, String msg)

多么可怕的失败:报告一个永远不会发生的情况。

static int wtf(String tag, Throwable tr)

多么糟糕的失败:报告一个永远不会发生的异常。

static int wtf(String tag, String msg, Throwable tr)

多么糟糕的失败:报告一个永远不会发生的异常。

Inherited methods

From class java.lang.Object

Constants

ASSERT

Added in API level 1
int ASSERT

println方法的优先级常量。

常量值:7(0x00000007)

DEBUG

Added in API level 1
int DEBUG

println方法的优先级常量; 使用Log.d.

常量值:3(0x00000003)

ERROR

Added in API level 1
int ERROR

println方法的优先级常量; 使用Log.e.

常数值:6(0x00000006)

INFO

Added in API level 1
int INFO

println方法的优先级常量; 使用Log.i.

常量值:4(0x00000004)

VERBOSE

Added in API level 1
int VERBOSE

println方法的优先级常量; 使用Log.v.

常量值:2(0x00000002)

WARN

Added in API level 1
int WARN

println方法的优先级常量; 使用Log.w.

常量值:5(0x00000005)

Public methods

d

Added in API level 1
int d (String tag, 
                String msg, 
                Throwable tr)

发送 DEBUG日志消息并记录异常。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
tr Throwable: An exception to log
Returns
int

d

Added in API level 1
int d (String tag, 
                String msg)

发送 DEBUG日志消息。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
Returns
int

e

Added in API level 1
int e (String tag, 
                String msg)

发送 ERROR日志消息。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
Returns
int

e

Added in API level 1
int e (String tag, 
                String msg, 
                Throwable tr)

发送 ERROR日志消息并记录异常。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
tr Throwable: An exception to log
Returns
int

getStackTraceString

Added in API level 1
String getStackTraceString (Throwable tr)

Handy函数从Throwable获取可记录的堆栈跟踪

Parameters
tr Throwable: An exception to log
Returns
String

i

Added in API level 1
int i (String tag, 
                String msg, 
                Throwable tr)

发送 INFO日志消息并记录异常。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
tr Throwable: An exception to log
Returns
int

i

Added in API level 1
int i (String tag, 
                String msg)

发送 INFO日志消息。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
Returns
int

isLoggable

Added in API level 1
boolean isLoggable (String tag, 
                int level)

检查指定标记的日志是否可以在指定级别登录。 任何标签的默认级别都设置为INFO。 这意味着任何高于和包括INFO的级别都将被记录。 在对日志记录方法进行任何调用之前,您应该检查是否应该记录您的标记。 您可以通过设置系统属性来更改默认级别:'setprop log.tag。<YOUR_LOG_TAG> <LEVEL>'其中level是VERBOSE,DEBUG,INFO,WARN,ERROR,ASSERT或SUPPRESS。 SUPPRESS将关闭您的标签的所有日志记录。 您还可以创建一个local.prop文件,其中包含以下内容:'log.tag。<YOUR_LOG_TAG> = <LEVEL>',并将其放在/data/local.prop中。

Parameters
tag String: The tag to check.
level int: The level to check.
Returns
boolean Whether or not that this is allowed to be logged.
Throws
IllegalArgumentException is thrown if the tag.length() > 23.

println

Added in API level 1
int println (int priority, 
                String tag, 
                String msg)

低级日志记录调用。

Parameters
priority int: The priority/type of this log message
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
Returns
int The number of bytes written.

v

Added in API level 1
int v (String tag, 
                String msg)

发送 VERBOSE日志消息。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
Returns
int

v

Added in API level 1
int v (String tag, 
                String msg, 
                Throwable tr)

发送 VERBOSE日志消息并记录异常。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
tr Throwable: An exception to log
Returns
int

w

Added in API level 1
int w (String tag, 
                Throwable tr)

Parameters
tag String
tr Throwable
Returns
int

w

Added in API level 1
int w (String tag, 
                String msg, 
                Throwable tr)

发送 WARN日志消息并记录异常。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
tr Throwable: An exception to log
Returns
int

w

Added in API level 1
int w (String tag, 
                String msg)

发送 WARN日志消息。

Parameters
tag String: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
msg String: The message you would like logged.
Returns
int

wtf

Added in API level 8
int wtf (String tag, 
                String msg)

多么可怕的失败:报告一个永远不会发生的情况。 该错误将始终以调用堆栈的级别ASSERT记录。 根据系统配置,报告可能被添加到DropBoxManager和/或该过程可能会立即通过错误对话框终止。

Parameters
tag String: Used to identify the source of a log message.
msg String: The message you would like logged.
Returns
int

wtf

Added in API level 8
int wtf (String tag, 
                Throwable tr)

多么糟糕的失败:报告一个永远不会发生的异常。 类似于wtf(String, String) ,但有一个例外。

Parameters
tag String: Used to identify the source of a log message.
tr Throwable: An exception to log.
Returns
int

wtf

Added in API level 8
int wtf (String tag, 
                String msg, 
                Throwable tr)

多么糟糕的失败:报告一个永远不会发生的异常。 类似于wtf(String, Throwable) ,并带有消息。

Parameters
tag String: Used to identify the source of a log message.
msg String: The message you would like logged.
tr Throwable: An exception to log. May be null.
Returns
int

Hooray!