Logpublic final class Log extends Object 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. |
Fields Summary |
---|
public static final int | VERBOSEPriority constant for the println method; use Log.v. | public static final int | DEBUGPriority constant for the println method; use Log.d. | public static final int | INFOPriority constant for the println method; use Log.i. | public static final int | WARNPriority constant for the println method; use Log.w. | public static final int | ERRORPriority constant for the println method; use Log.e. | public static final int | ASSERTPriority constant for the println method. |
Constructors Summary |
---|
private Log()
|
Methods Summary |
---|
public static int | d(java.lang.String tag, java.lang.String msg)Send a {@link #DEBUG} log message.
return println(DEBUG, tag, msg);
| public static int | d(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)Send a {@link #DEBUG} log message and log the exception.
return println(DEBUG, tag, msg + '\n" + getStackTraceString(tr));
| public static int | e(java.lang.String tag, java.lang.String msg)Send an {@link #ERROR} log message.
return println(ERROR, tag, msg);
| public static int | e(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)Send a {@link #ERROR} log message and log the exception.
int r = println(ERROR, tag, msg + '\n" + getStackTraceString(tr));
RuntimeInit.reportException(tag, tr, false); // asynchronous
return r;
| public static java.lang.String | getStackTraceString(java.lang.Throwable tr)Handy function to get a loggable stack trace from a Throwable
if (tr == null) {
return "";
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
tr.printStackTrace(pw);
return sw.toString();
| public static int | i(java.lang.String tag, java.lang.String msg)Send an {@link #INFO} log message.
return println(INFO, tag, msg);
| public static int | i(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)Send a {@link #INFO} log message and log the exception.
return println(INFO, tag, msg + '\n" + getStackTraceString(tr));
| public static native boolean | isLoggable(java.lang.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.<YOUR_LOG_TAG> <LEVEL>'
Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPRESS 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.
| public static native int | println(int priority, java.lang.String tag, java.lang.String msg)Low-level logging call.
| public static int | v(java.lang.String tag, java.lang.String msg)Send a {@link #VERBOSE} log message.
return println(VERBOSE, tag, msg);
| public static int | v(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)Send a {@link #VERBOSE} log message and log the exception.
return println(VERBOSE, tag, msg + '\n" + getStackTraceString(tr));
| public static int | w(java.lang.String tag, java.lang.Throwable tr)
return println(WARN, tag, getStackTraceString(tr));
| public static int | w(java.lang.String tag, java.lang.String msg)Send a {@link #WARN} log message.
return println(WARN, tag, msg);
| public static int | w(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)Send a {@link #WARN} log message and log the exception.
return println(WARN, tag, msg + '\n" + getStackTraceString(tr));
|
|