java.lang.Object | |
↳ | android.util.Log |
API for sending log output.
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.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ASSERT | Priority constant for the println method. | |||||||||
int | DEBUG | Priority constant for the println method; use Log.d. | |||||||||
int | ERROR | Priority constant for the println method; use Log.e. | |||||||||
int | INFO | Priority constant for the println method; use Log.i. | |||||||||
int | VERBOSE | Priority constant for the println method; use Log.v. | |||||||||
int | WARN | Priority constant for the println method; use Log.w. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Send a
DEBUG log message. | |||||||||||
Send a
DEBUG log message and log the exception. | |||||||||||
Send an
ERROR log message. | |||||||||||
Send a
ERROR log message and log the exception. | |||||||||||
Handy function to get a loggable stack trace from a Throwable
| |||||||||||
Send an
INFO log message. | |||||||||||
Send a
INFO log message and log the exception. | |||||||||||
Checks to see whether or not a log for the specified tag is loggable at the specified level.
| |||||||||||
Low-level logging call.
| |||||||||||
Send a
VERBOSE log message and log the exception. | |||||||||||
Send a
VERBOSE log message. | |||||||||||
Send a
WARN log message and log the exception. | |||||||||||
Send a
WARN log message. | |||||||||||
What a Terrible Failure: Report an exception that should never happen.
| |||||||||||
What a Terrible Failure: Report an exception that should never happen.
| |||||||||||
What a Terrible Failure: Report a condition that should never happen.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Priority constant for the println method.
Priority constant for the println method; use Log.d.
Priority constant for the println method; use Log.e.
Priority constant for the println method; use Log.i.
Priority constant for the println method; use Log.v.
Priority constant for the println method; use Log.w.
Send a 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. |
Send a 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 log |
Send an 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. |
Send a 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 log |
Handy function to get a loggable stack trace from a Throwable
tr | An exception to log |
---|
Send an 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. |
Send a 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 log |
Checks to see whether or not a log for the specified tag is loggable at the specified level. The default level of any tag is set to INFO. This means that any level above and including INFO will be logged. Before you make any calls to a logging method you should check to see if your tag should be logged. You can change the default level by setting a system property: 'setprop log.tag.<YOUR_LOG_TAG> <LEVEL>' Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will turn off all logging for your tag. You can also create a local.prop file that with the following in it: 'log.tag.<YOUR_LOG_TAG>=<LEVEL>' and place that in /data/local.prop.
tag | The tag to check. |
---|---|
level | The level to check. |
IllegalArgumentException | is thrown if the tag.length() > 23. |
---|
Low-level logging call.
priority | The priority/type of this 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. |
Send a 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 log |
Send a 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. |
Send a 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 log |
Send a 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. |
What a Terrible Failure: Report an exception that should never happen.
Similar to wtf(String, String)
, with an exception to log.
tag | Used to identify the source of a log message. |
---|---|
tr | An exception to log. |
What a Terrible Failure: Report an exception that should never happen.
Similar to 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. |
What a Terrible Failure: Report a condition that should never happen.
The error will always be logged at level ASSERT with the call stack.
Depending on system configuration, a report may be added to the
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. |