Merge "Revert "DO NOT MERGE Enhance local log."" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
771d210ab2
@@ -30,32 +30,20 @@ public final class LocalLog {
|
|||||||
private LinkedList<String> mLog;
|
private LinkedList<String> mLog;
|
||||||
private int mMaxLines;
|
private int mMaxLines;
|
||||||
private long mNow;
|
private long mNow;
|
||||||
private final boolean mKeepFirst;
|
|
||||||
|
|
||||||
public LocalLog(int maxLines) {
|
public LocalLog(int maxLines) {
|
||||||
mLog = new LinkedList<String>();
|
mLog = new LinkedList<String>();
|
||||||
mMaxLines = maxLines;
|
mMaxLines = maxLines;
|
||||||
mKeepFirst = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalLog(int maxLines, boolean keepFirst) {
|
|
||||||
mLog = new LinkedList<String>();
|
|
||||||
mMaxLines = maxLines;
|
|
||||||
mKeepFirst = keepFirst;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void log(String msg) {
|
public synchronized void log(String msg) {
|
||||||
mNow = System.currentTimeMillis();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
Calendar c = Calendar.getInstance();
|
|
||||||
c.setTimeInMillis(mNow);
|
|
||||||
sb.append(String.format("%tm-%td %tH:%tM:%tS.%tL", c, c, c, c, c, c));
|
|
||||||
logStraight(sb.toString() + " - " + msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void logStraight(String msg) {
|
|
||||||
if (mKeepFirst == false || mLog.size() < mMaxLines) mLog.add(msg);
|
|
||||||
if (mMaxLines > 0) {
|
if (mMaxLines > 0) {
|
||||||
|
mNow = System.currentTimeMillis();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTimeInMillis(mNow);
|
||||||
|
sb.append(String.format("%tm-%td %tH:%tM:%tS.%tL", c, c, c, c, c, c));
|
||||||
|
mLog.add(sb.toString() + " - " + msg);
|
||||||
while (mLog.size() > mMaxLines) mLog.remove();
|
while (mLog.size() > mMaxLines) mLog.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,13 +74,4 @@ public final class LocalLog {
|
|||||||
public ReadOnlyLocalLog readOnlyLocalLog() {
|
public ReadOnlyLocalLog readOnlyLocalLog() {
|
||||||
return new ReadOnlyLocalLog(this);
|
return new ReadOnlyLocalLog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void copyTo(LocalLog other, int lines) {
|
|
||||||
int end = mLog.size()-1;
|
|
||||||
int begin = end - lines;
|
|
||||||
if (begin < 0) begin = 0;
|
|
||||||
for (; begin < end; begin++) {
|
|
||||||
other.logStraight(mLog.get(begin));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user