Logpublic 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 void | d(java.lang.String tag, java.lang.String message)Outputs a {@link LogLevel#DEBUG} level message.
println(LogLevel.DEBUG, tag, message);
| public static void | e(java.lang.String tag, java.lang.String message)Outputs a {@link LogLevel#ERROR} level message.
println(LogLevel.ERROR, tag, message);
| public static void | e(java.lang.String tag, java.lang.Throwable throwable)Outputs a {@link LogLevel#ERROR} level {@link Throwable} information.
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 void | hexDump(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 void | hexDump(byte[] data)Dump the entire contents of a byte array with DEBUG priority.
hexDump("ddms", LogLevel.DEBUG, data, 0, data.length);
| public static void | i(java.lang.String tag, java.lang.String message)Outputs a {@link LogLevel#INFO} level message.
println(LogLevel.INFO, tag, message);
| public static void | logAndDisplay(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.
if (sLogOutput != null) {
sLogOutput.printAndPromptLog(logLevel, tag, message);
} else {
println(logLevel, tag, message);
}
| public static void | printLog(com.android.ddmlib.Log$LogLevel logLevel, java.lang.String tag, java.lang.String message)Prints a log 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 void | println(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 void | setLevel(com.android.ddmlib.Log$LogLevel logLevel)
mLevel = logLevel;
| public static void | setLogOutput(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.
sLogOutput = logOutput;
| public static void | v(java.lang.String tag, java.lang.String message)Outputs a {@link LogLevel#VERBOSE} level message.
println(LogLevel.VERBOSE, tag, message);
| public static void | w(java.lang.String tag, java.lang.String message)Outputs a {@link LogLevel#WARN} level message.
println(LogLevel.WARN, tag, message);
|
|