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

Commit 492f1030 authored by Alex Dadukin's avatar Alex Dadukin Committed by Android (Google) Code Review
Browse files

Merge "Conduct non-functional refactoring for EventLogger"

parents ced499e5 183bde5d
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -25,20 +25,32 @@ import java.lang.annotation.RetentionPolicy;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.Locale;

/**
 * Logs human-readable events for debugging purposes.
 */
public class EventLogger {

    // ring buffer of events to log.
    private final LinkedList<Event> mEvents;
    /** Identifies the source of events. */
    private final String mTag;

    private final String mTitle;
    /** Stores the events using a ring buffer. */
    private final LinkedList<Event> mEvents;

    // the maximum number of events to keep in log
    /**
     * The maximum number of events to keep in {@code mEvents}.
     *
     * <p>Calling {@link #log} when the size of {@link #mEvents} matches the threshold will
     * cause the oldest event to be evicted.
     */
    private final int mMemSize;

    public static abstract class Event {
        // formatter for timestamps
        private final static SimpleDateFormat sFormat = new SimpleDateFormat("MM-dd HH:mm:ss:SSS");
    public abstract static class Event {

        /** Timestamps formatter. */
        private static final SimpleDateFormat sFormat =
                new SimpleDateFormat("MM-dd HH:mm:ss:SSS", Locale.US);

        private final long mTimestamp;

@@ -114,7 +126,7 @@ public class EventLogger {
         * Timestamp information will be automatically added, do not include it.
         * @return a string representation of the event that occurred.
         */
        abstract public String eventToString();
        public abstract String eventToString();
    }

    public static class StringEvent extends Event {
@@ -133,12 +145,12 @@ public class EventLogger {
    /**
     * Constructor for logger.
     * @param size the maximum number of events to keep in log
     * @param title the string displayed before the recorded log
     * @param tag the string displayed before the recorded log
     */
    public EventLogger(int size, String title) {
    public EventLogger(int size, String tag) {
        mEvents = new LinkedList<Event>();
        mMemSize = size;
        mTitle = title;
        mTag = tag;
    }

    public synchronized void log(Event evt) {
@@ -170,7 +182,7 @@ public class EventLogger {
    }

    public synchronized void dump(PrintWriter pw) {
        pw.println("Audio event log: " + mTitle);
        pw.println("Events log: " + mTag);
        for (Event evt : mEvents) {
            pw.println(evt.toString());
        }