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

Commit 1c8f780d authored by Alex Dadukin's avatar Alex Dadukin
Browse files

Move EventLogger.Event definition to the bottom of the outer class

Bug: b/243116883
Test: N/A
Change-Id: I7964191d1a8681a243ada2f2a46a1d8a8c091bf9
parent 492f1030
Loading
Loading
Loading
Loading
+46 −46
Original line number Diff line number Diff line
@@ -46,6 +46,52 @@ public class EventLogger {
     */
    private final int mMemSize;

    /**
     * Constructor for logger.
     * @param size the maximum number of events to keep in log
     * @param tag the string displayed before the recorded log
     */
    public EventLogger(int size, String tag) {
        mEvents = new LinkedList<Event>();
        mMemSize = size;
        mTag = tag;
    }

    public synchronized void log(Event evt) {
        if (mEvents.size() >= mMemSize) {
            mEvents.removeFirst();
        }
        mEvents.add(evt);
    }

    /**
     * Add a string-based event to the log, and print it to logcat as info.
     * @param msg the message for the logs
     * @param tag the logcat tag to use
     */
    public synchronized void loglogi(String msg, String tag) {
        final Event event = new StringEvent(msg);
        log(event.printLog(tag));
    }

    /**
     * Same as {@link #loglogi(String, String)} but specifying the logcat type
     * @param msg the message for the logs
     * @param logType the type of logcat entry
     * @param tag the logcat tag to use
     */
    public synchronized void loglog(String msg, @Event.LogType int logType, String tag) {
        final Event event = new StringEvent(msg);
        log(event.printLog(logType, tag));
    }

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

    public abstract static class Event {

        /** Timestamps formatter. */
@@ -141,50 +187,4 @@ public class EventLogger {
            return mMsg;
        }
    }

    /**
     * Constructor for logger.
     * @param size the maximum number of events to keep in log
     * @param tag the string displayed before the recorded log
     */
    public EventLogger(int size, String tag) {
        mEvents = new LinkedList<Event>();
        mMemSize = size;
        mTag = tag;
    }

    public synchronized void log(Event evt) {
        if (mEvents.size() >= mMemSize) {
            mEvents.removeFirst();
        }
        mEvents.add(evt);
    }

    /**
     * Add a string-based event to the log, and print it to logcat as info.
     * @param msg the message for the logs
     * @param tag the logcat tag to use
     */
    public synchronized void loglogi(String msg, String tag) {
        final Event event = new StringEvent(msg);
        log(event.printLog(tag));
    }

    /**
     * Same as {@link #loglogi(String, String)} but specifying the logcat type
     * @param msg the message for the logs
     * @param logType the type of logcat entry
     * @param tag the logcat tag to use
     */
    public synchronized void loglog(String msg, @Event.LogType int logType, String tag) {
        final Event event = new StringEvent(msg);
        log(event.printLog(logType, tag));
    }

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