diff --git a/services/core/java/com/android/server/utils/EventLogger.java b/services/core/java/com/android/server/utils/EventLogger.java index 321edc5287783..f3a60cee8728e 100644 --- a/services/core/java/com/android/server/utils/EventLogger.java +++ b/services/core/java/com/android/server/utils/EventLogger.java @@ -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. + /** Identifies the source of events. */ + private final String mTag; + + /** Stores the events using a ring buffer. */ private final LinkedList mEvents; - private final String mTitle; - - // the maximum number of events to keep in log + /** + * The maximum number of events to keep in {@code mEvents}. + * + *

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(); 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()); }