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

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

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

parents 451566c1 1c8f780d
Loading
Loading
Loading
Loading
+46 −46
Original line number Original line Diff line number Diff line
@@ -46,6 +46,52 @@ public class EventLogger {
     */
     */
    private final int mMemSize;
    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 {
    public abstract static class Event {


        /** Timestamps formatter. */
        /** Timestamps formatter. */
@@ -141,50 +187,4 @@ public class EventLogger {
            return mMsg;
            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());
        }
    }
}
}