public final class Log extends Object
Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e() methods.
The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.
Tip: A good convention is to declare a TAG
constant
in your class:
private static final String TAG = "MyActivity";and use that in subsequent calls to the log methods.
Tip: Don't forget that when you make a call like
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.
Modifier and Type | Class and Description |
---|---|
static interface |
Log.TerribleFailureHandler
Interface to handle terrible failures from
wtf(java.lang.String, java.lang.String) . |
Modifier and Type | Field and Description |
---|---|
static int |
ASSERT
Priority constant for the println method.
|
static int |
DEBUG
Priority constant for the println method; use Log.d.
|
static int |
ERROR
Priority constant for the println method; use Log.e.
|
static int |
INFO
Priority constant for the println method; use Log.i.
|
static int |
LOG_ID_CRASH |
static int |
LOG_ID_EVENTS |
static int |
LOG_ID_MAIN |
static int |
LOG_ID_RADIO |
static int |
LOG_ID_SYSTEM |
static int |
VERBOSE
Priority constant for the println method; use Log.v.
|
static int |
WARN
Priority constant for the println method; use Log.w.
|
Modifier and Type | Method and Description |
---|---|
static int |
d(String tag,
String msg)
Send a
DEBUG log message. |
static int |
d(String tag,
String msg,
Throwable tr)
Send a
DEBUG log message and log the exception. |
static int |
e(String tag,
String msg)
Send an
ERROR log message. |
static int |
e(String tag,
String msg,
Throwable tr)
Send a
ERROR log message and log the exception. |
static String |
getStackTraceString(Throwable tr)
Handy function to get a loggable stack trace from a Throwable
|
static int |
i(String tag,
String msg)
Send an
INFO log message. |
static int |
i(String tag,
String msg,
Throwable tr)
Send a
INFO log message and log the exception. |
static boolean |
isLoggable(String tag,
int level)
Checks to see whether or not a log for the specified tag is loggable at the specified level.
|
static int |
println_native(int bufID,
int priority,
String tag,
String msg) |
static int |
println(int priority,
String tag,
String msg)
Low-level logging call.
|
static int |
printlns(int bufID,
int priority,
String tag,
String msg,
Throwable tr)
Helper function for long messages.
|
static Log.TerribleFailureHandler |
setWtfHandler(Log.TerribleFailureHandler handler)
Sets the terrible failure handler, for testing.
|
static int |
v(String tag,
String msg)
Send a
VERBOSE log message. |
static int |
v(String tag,
String msg,
Throwable tr)
Send a
VERBOSE log message and log the exception. |
static int |
w(String tag,
String msg)
Send a
WARN log message. |
static int |
w(String tag,
String msg,
Throwable tr)
Send a
WARN log message and log the exception. |
static int |
w(String tag,
Throwable tr) |
static int |
wtf(String tag,
String msg)
What a Terrible Failure: Report a condition that should never happen.
|
static int |
wtf(String tag,
String msg,
Throwable tr)
What a Terrible Failure: Report an exception that should never happen.
|
static int |
wtf(String tag,
Throwable tr)
What a Terrible Failure: Report an exception that should never happen.
|
static int |
wtfStack(String tag,
String msg)
Like
wtf(String, String) , but also writes to the log the full
call stack. |
public static final int VERBOSE
public static final int DEBUG
public static final int INFO
public static final int WARN
public static final int ERROR
public static final int ASSERT
public static final int LOG_ID_MAIN
public static final int LOG_ID_RADIO
public static final int LOG_ID_EVENTS
public static final int LOG_ID_SYSTEM
public static final int LOG_ID_CRASH
public static int v(String tag, String msg)
VERBOSE
log message.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.public static int v(String tag, String msg, Throwable tr)
VERBOSE
log message and log the exception.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.tr
- An exception to logpublic static int d(String tag, String msg)
DEBUG
log message.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.public static int d(String tag, String msg, Throwable tr)
DEBUG
log message and log the exception.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.tr
- An exception to logpublic static int i(String tag, String msg)
INFO
log message.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.public static int i(String tag, String msg, Throwable tr)
INFO
log message and log the exception.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.tr
- An exception to logpublic static int w(String tag, String msg)
WARN
log message.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.public static int w(String tag, String msg, Throwable tr)
WARN
log message and log the exception.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.tr
- An exception to logpublic static boolean isLoggable(String tag, int level)
tag
- The tag to check.level
- The level to check.IllegalArgumentException
- is thrown if the tag.length() > 23.public static int e(String tag, String msg)
ERROR
log message.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.public static int e(String tag, String msg, Throwable tr)
ERROR
log message and log the exception.tag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.tr
- An exception to logpublic static int wtf(String tag, String msg)
DropBoxManager
and/or the process may be terminated
immediately with an error dialog.tag
- Used to identify the source of a log message.msg
- The message you would like logged.public static int wtfStack(String tag, String msg)
wtf(String, String)
, but also writes to the log the full
call stack.public static int wtf(String tag, Throwable tr)
wtf(String, String)
, with an exception to log.tag
- Used to identify the source of a log message.tr
- An exception to log.public static int wtf(String tag, String msg, Throwable tr)
wtf(String, Throwable)
, with a message as well.tag
- Used to identify the source of a log message.msg
- The message you would like logged.tr
- An exception to log. May be null.public static Log.TerribleFailureHandler setWtfHandler(Log.TerribleFailureHandler handler)
public static String getStackTraceString(Throwable tr)
tr
- An exception to logpublic static int println(int priority, String tag, String msg)
priority
- The priority/type of this log messagetag
- Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.msg
- The message you would like logged.