↳
android.util.Log
Class Overview
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 likeLog.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
Priority constant for the println method.
int
Priority constant for the println method; use Log.d.
int
Priority constant for the println method; use Log.e.
int
Priority constant for the println method; use Log.i.
int
Priority constant for the println method; use Log.v.
int
Priority constant for the println method; use Log.w.
Public Methods
static
int
Send a
static
int
Send a
static
int
Send an
static
int
Send a
static
String
Handy function to get a loggable stack trace from a Throwable
static
int
Send an
static
int
Send a
static
boolean
String tag, int level)
Checks to see whether or not a log for the specified tag is loggable at the specified level.
static
int
String tag, String msg)
Low-level logging call.
static
int
Send a
static
int
Send a
static
int
static
int
Send a
static
int
Send a
static
int
What a Terrible Failure: Report an exception that should never happen.
static
int
What a Terrible Failure: Report a condition that should never happen.
static
int
What a Terrible Failure: Report an exception that should never happen.
[Expand]
Inherited Methods
From class
java.lang.Object
Creates and returns a copy of this Object.
boolean
Compares this instance with the specified object and indicates if they
are equal.
void
Invoked when the garbage collector has detected that this instance is no longer reachable.
final
Class>
Returns the unique instance of
int
Returns an integer hash code for this object.
final
void
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
final
void
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
Returns a string containing a concise, human-readable description of this
object.
final
void
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
final
void
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
final
void
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
Constants
public
static
final
int
ASSERT
Priority constant for the println method.
Constant Value:
7
(0x00000007)
public
static
final
int
DEBUG
Priority constant for the println method; use Log.d.
Constant Value:
3
(0x00000003)
public
static
final
int
ERROR
Priority constant for the println method; use Log.e.
Constant Value:
6
(0x00000006)
public
static
final
int
INFO
Priority constant for the println method; use Log.i.
Constant Value:
4
(0x00000004)
public
static
final
int
VERBOSE
Priority constant for the println method; use Log.v.
Constant Value:
2
(0x00000002)
public
static
final
int
WARN
Priority constant for the println method; use Log.w.
Constant Value:
5
(0x00000005)
Public Methods
public
static
int
d
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
public
static
int
d
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
trAn exception to log
public
static
int
e
Send an
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
public
static
int
e
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
trAn exception to log
public
static
String
getStackTraceString
Handy function to get a loggable stack trace from a Throwable
Parameters
trAn exception to log
public
static
int
i
Send an
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
public
static
int
i
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
trAn exception to log
public
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.
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.'
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.='
and place that in /data/local.prop.
Parameters
tagThe tag to check.
levelThe level to check.
Returns
Whether or not that this is allowed to be logged.
Throws
is thrown if the tag.length() > 23.
public
static
int
println
(int priority, String tag, String msg)
Low-level logging call.
Parameters
priorityThe priority/type of this log message
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
Returns
The number of bytes written.
public
static
int
v
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
public
static
int
v
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
trAn exception to log
public
static
int
w
public
static
int
w
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
trAn exception to log
public
static
int
w
Send a
Parameters
tagUsed to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
msgThe message you would like logged.
public
static
int
wtf
What a Terrible Failure: Report an exception that should never happen.
Similar to
Parameters
tagUsed to identify the source of a log message.
trAn exception to log.
public
static
int
wtf
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
Parameters
tagUsed to identify the source of a log message.
msgThe message you would like logged.
public
static
int
wtf
What a Terrible Failure: Report an exception that should never happen.
Similar to
Parameters
tagUsed to identify the source of a log message.
msgThe message you would like logged.
trAn exception to log. May be null.
Except as noted, this content is licensed under Apache 2.0.
For details and restrictions, see the Content License.
Android 4.4 r1 —