FileDocCategorySizeDatePackage
EventLog.javaAPI DocAndroid 5.1 API9858Thu Mar 12 22:22:10 GMT 2015android.util

EventLog

public 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()

hide

Methods Summary
public static intgetTagCode(java.lang.String name)
Get the event type tag code associated with an event name.

param
name of event to look up
return
the tag code, or -1 if no tag has that name

        readTagsFile();
        Integer code = sTagCodes.get(name);
        return code != null ? code : -1;
    
public static java.lang.StringgetTagName(int tag)
Get the name associated with an event type tag code.

param
tag code to look up
return
the name of the tag, or null if no tag has that number

        readTagsFile();
        return sTagNames.get(tag);
    
public static native voidreadEvents(int[] tags, java.util.Collection output)
Read events from the log, filtered by type.

param
tags to search for
param
output container to add events into
throws
IOException if something goes wrong reading events

private static synchronized voidreadTagsFile()
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 intwriteEvent(int tag, int value)
Record an event log message.

param
tag The event type tag code
param
value A value to log
return
The number of bytes written

public static native intwriteEvent(int tag, long value)
Record an event log message.

param
tag The event type tag code
param
value A value to log
return
The number of bytes written

public static native intwriteEvent(int tag, java.lang.String str)
Record an event log message.

param
tag The event type tag code
param
str A value to log
return
The number of bytes written

public static native intwriteEvent(int tag, java.lang.Object list)
Record an event log message.

param
tag The event type tag code
param
list A list of values to log
return
The number of bytes written