FileDocCategorySizeDatePackage
Log.javaAPI DocAndroid 1.5 API9198Wed May 06 22:41:56 BST 2009android.util

Log

public 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
VERBOSE
Priority constant for the println method; use Log.v.
public static final int
DEBUG
Priority constant for the println method; use Log.d.
public static final int
INFO
Priority constant for the println method; use Log.i.
public static final int
WARN
Priority constant for the println method; use Log.w.
public static final int
ERROR
Priority constant for the println method; use Log.e.
public static final int
ASSERT
Priority constant for the println method.
Constructors Summary
private Log()


      
    
Methods Summary
public static intd(java.lang.String tag, java.lang.String msg)
Send a {@link #DEBUG} log message.

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

        return println(DEBUG, tag, msg);
    
public static intd(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)
Send a {@link #DEBUG} log message and log the exception.

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

        return println(DEBUG, tag, msg + '\n" + getStackTraceString(tr));
    
public static inte(java.lang.String tag, java.lang.String msg)
Send an {@link #ERROR} log message.

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

        return println(ERROR, tag, msg);
    
public static inte(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)
Send a {@link #ERROR} log message and log the exception.

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

        int r = println(ERROR, tag, msg + '\n" + getStackTraceString(tr));
        RuntimeInit.reportException(tag, tr, false);  // asynchronous
        return r;
    
public static java.lang.StringgetStackTraceString(java.lang.Throwable tr)
Handy function to get a loggable stack trace from a Throwable

param
tr An exception to log

        if (tr == null) {
            return "";
        }
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        tr.printStackTrace(pw);
        return sw.toString();
    
public static inti(java.lang.String tag, java.lang.String msg)
Send an {@link #INFO} log message.

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

        return println(INFO, tag, msg);
    
public static inti(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)
Send a {@link #INFO} log message and log the exception.

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

        return println(INFO, tag, msg + '\n" + getStackTraceString(tr));
    
public static native booleanisLoggable(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.

param
tag The tag to check.
param
level The level to check.
return
Whether or not that this is allowed to be logged.
throws
IllegalArgumentException is thrown if the tag.length() > 23.

public static native intprintln(int priority, java.lang.String tag, java.lang.String msg)
Low-level logging call.

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

public static intv(java.lang.String tag, java.lang.String msg)
Send a {@link #VERBOSE} log message.

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

        return println(VERBOSE, tag, msg);
    
public static intv(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)
Send a {@link #VERBOSE} log message and log the exception.

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

        return println(VERBOSE, tag, msg + '\n" + getStackTraceString(tr));
    
public static intw(java.lang.String tag, java.lang.Throwable tr)

        return println(WARN, tag, getStackTraceString(tr));
    
public static intw(java.lang.String tag, java.lang.String msg)
Send a {@link #WARN} log message.

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

        return println(WARN, tag, msg);
    
public static intw(java.lang.String tag, java.lang.String msg, java.lang.Throwable tr)
Send a {@link #WARN} log message and log the exception.

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

        return println(WARN, tag, msg + '\n" + getStackTraceString(tr));