EventLogpublic class EventLog extends Object Access to the system diagnostic event record. System diagnostic events are
used to record certain system-level events (such as garbage collection,
activity manager state, system watchdogs, and other low level activity),
which may be automatically collected and analyzed during system development.
This is not the main "logcat" debugging log ({@link android.util.Log})!
These diagnostic events are for system integrators, not application authors.
Events use integer tag codes corresponding to /system/etc/event-log-tags.
They carry a payload of one or more int, long, or String values. The
event-log-tags file defines the payload contents for each type code. |
Fields Summary |
---|
private static final String | TAG | private static final String | TAGS_FILE | private static final String | COMMENT_PATTERN | private static final String | TAG_PATTERN | private static HashMap | sTagCodes | private static HashMap | sTagNames |
Constructors Summary |
---|
public EventLog()
|
Methods Summary |
---|
public static int | getTagCode(java.lang.String name)Get the event type tag code associated with an event name.
readTagsFile();
Integer code = sTagCodes.get(name);
return code != null ? code : -1;
| public static java.lang.String | getTagName(int tag)Get the name associated with an event type tag code.
readTagsFile();
return sTagNames.get(tag);
| public static native void | readEvents(int[] tags, java.util.Collection output)Read events from the log, filtered by type.
| private static synchronized void | readTagsFile()Read TAGS_FILE, populating sTagCodes and sTagNames, if not already done.
if (sTagCodes != null && sTagNames != null) return;
sTagCodes = new HashMap<String, Integer>();
sTagNames = new HashMap<Integer, String>();
Pattern comment = Pattern.compile(COMMENT_PATTERN);
Pattern tag = Pattern.compile(TAG_PATTERN);
BufferedReader reader = null;
String line;
try {
reader = new BufferedReader(new FileReader(TAGS_FILE), 256);
while ((line = reader.readLine()) != null) {
if (comment.matcher(line).matches()) continue;
Matcher m = tag.matcher(line);
if (!m.matches()) {
Log.wtf(TAG, "Bad entry in " + TAGS_FILE + ": " + line);
continue;
}
try {
int num = Integer.parseInt(m.group(1));
String name = m.group(2);
sTagCodes.put(name, num);
sTagNames.put(num, name);
} catch (NumberFormatException e) {
Log.wtf(TAG, "Error in " + TAGS_FILE + ": " + line, e);
}
}
} catch (IOException e) {
Log.wtf(TAG, "Error reading " + TAGS_FILE, e);
// Leave the maps existing but unpopulated
} finally {
try { if (reader != null) reader.close(); } catch (IOException e) {}
}
| public static native int | writeEvent(int tag, int value)Record an event log message.
| public static native int | writeEvent(int tag, long value)Record an event log message.
| public static native int | writeEvent(int tag, java.lang.String str)Record an event log message.
| public static native int | writeEvent(int tag, java.lang.Object list)Record an event log message.
|
|