FileDocCategorySizeDatePackage
Log.javaAPI DocAndroid 1.5 API11193Wed May 06 22:41:08 BST 2009com.android.ddmlib

Log

public final class Log extends Object
Log class that mirrors the API in main Android sources.

Default behavior outputs the log to {@link System#out}. Use {@link #setLogOutput(com.android.ddmlib.Log.ILogOutput)} to redirect the log somewhere else.

Fields Summary
private static LogLevel
mLevel
private static ILogOutput
sLogOutput
private static final char[]
mSpaceLine
private static final char[]
mHexDigit
Constructors Summary
private Log()

    

      
Methods Summary
public static voidd(java.lang.String tag, java.lang.String message)
Outputs a {@link LogLevel#DEBUG} level message.

param
tag The tag associated with the message.
param
message The message to output.

        println(LogLevel.DEBUG, tag, message);
    
public static voide(java.lang.String tag, java.lang.String message)
Outputs a {@link LogLevel#ERROR} level message.

param
tag The tag associated with the message.
param
message The message to output.

        println(LogLevel.ERROR, tag, message);
    
public static voide(java.lang.String tag, java.lang.Throwable throwable)
Outputs a {@link LogLevel#ERROR} level {@link Throwable} information.

param
tag The tag associated with the message.
param
throwable The {@link Throwable} to output.

        if (throwable != null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);

            throwable.printStackTrace(pw);
            println(LogLevel.ERROR, tag, throwable.getMessage() + '\n" + sw.toString());
        }
    
static voidhexDump(java.lang.String tag, com.android.ddmlib.Log$LogLevel level, byte[] data, int offset, int length)
Show hex dump.

Local addition. Output looks like: 1230- 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef

Uses no string concatenation; creates one String object per line.


        int kHexOffset = 6;
        int kAscOffset = 55;
        char[] line = new char[mSpaceLine.length];
        int addr, baseAddr, count;
        int i, ch;
        boolean needErase = true;

        //Log.w(tag, "HEX DUMP: off=" + offset + ", length=" + length);

        baseAddr = 0;
        while (length != 0) {
            if (length > 16) {
                // full line
                count = 16;
            } else {
                // partial line; re-copy blanks to clear end
                count = length;
                needErase = true;
            }

            if (needErase) {
                System.arraycopy(mSpaceLine, 0, line, 0, mSpaceLine.length);
                needErase = false;
            }

            // output the address (currently limited to 4 hex digits)
            addr = baseAddr;
            addr &= 0xffff;
            ch = 3;
            while (addr != 0) {
                line[ch] = mHexDigit[addr & 0x0f];
                ch--;
                addr >>>= 4;
            }

            // output hex digits and ASCII chars
            ch = kHexOffset;
            for (i = 0; i < count; i++) {
                byte val = data[offset + i];

                line[ch++] = mHexDigit[(val >>> 4) & 0x0f];
                line[ch++] = mHexDigit[val & 0x0f];
                ch++;

                if (val >= 0x20 && val < 0x7f)
                    line[kAscOffset + i] = (char) val;
                else
                    line[kAscOffset + i] = '.";
            }

            println(level, tag, new String(line));

            // advance to next chunk of data
            length -= count;
            offset += count;
            baseAddr += count;
        }

    
static voidhexDump(byte[] data)
Dump the entire contents of a byte array with DEBUG priority.

        hexDump("ddms", LogLevel.DEBUG, data, 0, data.length);
    
public static voidi(java.lang.String tag, java.lang.String message)
Outputs a {@link LogLevel#INFO} level message.

param
tag The tag associated with the message.
param
message The message to output.

        println(LogLevel.INFO, tag, message);
    
public static voidlogAndDisplay(com.android.ddmlib.Log$LogLevel logLevel, java.lang.String tag, java.lang.String message)
Outputs a log message and attempts to display it in a dialog.

param
tag The tag associated with the message.
param
message The message to output.

        if (sLogOutput != null) {
            sLogOutput.printAndPromptLog(logLevel, tag, message);
        } else {
            println(logLevel, tag, message);
        }
    
public static voidprintLog(com.android.ddmlib.Log$LogLevel logLevel, java.lang.String tag, java.lang.String message)
Prints a log message.

param
logLevel
param
tag
param
message

        long msec;
        
        msec = System.currentTimeMillis();
        String outMessage = String.format("%02d:%02d %c/%s: %s\n",
                (msec / 60000) % 60, (msec / 1000) % 60,
                logLevel.getPriorityLetter(), tag, message);
        System.out.print(outMessage);
    
private static voidprintln(com.android.ddmlib.Log$LogLevel logLevel, java.lang.String tag, java.lang.String message)

        if (logLevel.getPriority() >= mLevel.getPriority()) {
            if (sLogOutput != null) {
                sLogOutput.printLog(logLevel, tag, message);
            } else {
                printLog(logLevel, tag, message);
            }
        }
    
static voidsetLevel(com.android.ddmlib.Log$LogLevel logLevel)

        mLevel = logLevel;
    
public static voidsetLogOutput(com.android.ddmlib.Log$ILogOutput logOutput)
Sets the {@link ILogOutput} to use to print the logs. If not set, {@link System#out} will be used.

param
logOutput The {@link ILogOutput} to use to print the log.

        sLogOutput = logOutput;
    
public static voidv(java.lang.String tag, java.lang.String message)
Outputs a {@link LogLevel#VERBOSE} level message.

param
tag The tag associated with the message.
param
message The message to output.

        println(LogLevel.VERBOSE, tag, message);
    
public static voidw(java.lang.String tag, java.lang.String message)
Outputs a {@link LogLevel#WARN} level message.

param
tag The tag associated with the message.
param
message The message to output.

        println(LogLevel.WARN, tag, message);