| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.util; |
| 18 |
|
| 19 |
import android.util.IndentingPrintWriter; |
| 20 |
import android.util.Slog; |
| 21 |
import android.util.proto.ProtoOutputStream; |
| 22 |
|
| 23 |
import java.util.ArrayList; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class LocalLog { |
| 32 |
private final String mTag; |
| 33 |
private final int mMaxLines = 20; |
| 34 |
private final ArrayList<String> mLines = new ArrayList<String>(mMaxLines); |
| 35 |
|
| 36 |
public LocalLog(String tag) { |
| 37 |
mTag = tag; |
| 38 |
} |
| 39 |
|
| 40 |
public void w(String msg) { |
| 41 |
synchronized (mLines) { |
| 42 |
Slog.w(mTag, msg); |
| 43 |
if (mLines.size() >= mMaxLines) { |
| 44 |
mLines.remove(0); |
| 45 |
} |
| 46 |
mLines.add(msg); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
public boolean dump(IndentingPrintWriter pw, String header) { |
| 51 |
synchronized (mLines) { |
| 52 |
if (mLines.size() <= 0) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
if (header != null) { |
| 56 |
pw.println(header); |
| 57 |
pw.increaseIndent(); |
| 58 |
} |
| 59 |
for (int i=0; i<mLines.size(); i++) { |
| 60 |
pw.println(mLines.get(i)); |
| 61 |
} |
| 62 |
if (header != null) { |
| 63 |
pw.decreaseIndent(); |
| 64 |
} |
| 65 |
return true; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public void dumpDebug(ProtoOutputStream proto, long fieldId) { |
| 70 |
final long token = proto.start(fieldId); |
| 71 |
|
| 72 |
synchronized (mLines) { |
| 73 |
for (int i = 0; i < mLines.size(); ++i) { |
| 74 |
proto.write(LocalLogProto.LINES, mLines.get(i)); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
proto.end(token); |
| 79 |
} |
| 80 |
} |