Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58b2d330 authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android Git Automerger
Browse files

am 0b9624d4: am 98961ea0: am 7385aca1: am f0bead28: Merge "DO NOT MERGE...

am 0b9624d4: am 98961ea0: am 7385aca1: am f0bead28: Merge "DO NOT MERGE Enhance local log." into mnc-dev

* commit '0b9624d4':
  DO NOT MERGE Enhance local log.
parents 54e9686d 0b9624d4
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -30,20 +30,32 @@ public final class LocalLog {
    private LinkedList<String> mLog;
    private int mMaxLines;
    private long mNow;
    private final boolean mKeepFirst;

    public LocalLog(int maxLines) {
        mLog = new LinkedList<String>();
        mMaxLines = maxLines;
        mKeepFirst = false;
    }

    public LocalLog(int maxLines, boolean keepFirst) {
        mLog = new LinkedList<String>();
        mMaxLines = maxLines;
        mKeepFirst = keepFirst;
    }

    public synchronized void log(String msg) {
        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);
        logStraight(sb.toString() + " - " + msg);
    }

    private synchronized void logStraight(String msg) {
        if (mKeepFirst == false || mLog.size() < mMaxLines) mLog.add(msg);
        if (mMaxLines > 0) {
            while (mLog.size() > mMaxLines) mLog.remove();
        }
    }
@@ -74,4 +86,13 @@ public final class LocalLog {
    public ReadOnlyLocalLog readOnlyLocalLog() {
        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));
        }
    }
}