Fields Summary |
---|
private static final Logger | LOGused to log messages |
private static final Comparator | MY_COMPuse the compare logging events |
private static final String[] | COL_NAMESnames of the columns in the table |
private static final EventDetails[] | EMPTY_LISTdefinition of an empty list |
private static final DateFormat | DATE_FORMATTERused to format dates |
private final Object | mLockthe lock to control access |
private final SortedSet | mAllEventsset of all logged events - not filtered |
private EventDetails[] | mFilteredEventsevents that are visible after filtering |
private final List | mPendingEventslist of events that are buffered for processing |
private boolean | mPausedindicates whether event collection is paused to the UI |
private String | mThreadFilterfilter for the thread |
private String | mMessageFilterfilter for the message |
private String | mNDCFilterfilter for the NDC |
private String | mCategoryFilterfilter for the category |
private Priority | mPriorityFilterfilter for the priority |
Methods Summary |
---|
public void | addEvent(org.apache.log4j.chainsaw.EventDetails aEvent)Add an event to the list.
synchronized (mLock) {
mPendingEvents.add(aEvent);
}
|
public void | clear()Clear the list of all events.
synchronized (mLock) {
mAllEvents.clear();
mFilteredEvents = new EventDetails[0];
mPendingEvents.clear();
fireTableDataChanged();
}
|
public java.lang.Class | getColumnClass(int aCol)
// does not need to be synchronized
return (aCol == 2) ? Boolean.class : Object.class;
|
public int | getColumnCount()
// does not need to be synchronized
return COL_NAMES.length;
|
public java.lang.String | getColumnName(int aCol)
// does not need to be synchronized
return COL_NAMES[aCol];
|
public org.apache.log4j.chainsaw.EventDetails | getEventDetails(int aRow)Get the throwable information at a specified row in the filtered events.
synchronized (mLock) {
return mFilteredEvents[aRow];
}
|
public int | getRowCount()
synchronized (mLock) {
return mFilteredEvents.length;
}
|
public java.lang.Object | getValueAt(int aRow, int aCol)
synchronized (mLock) {
final EventDetails event = mFilteredEvents[aRow];
if (aCol == 0) {
return DATE_FORMATTER.format(new Date(event.getTimeStamp()));
} else if (aCol == 1) {
return event.getPriority();
} else if (aCol == 2) {
return (event.getThrowableStrRep() == null)
? Boolean.FALSE : Boolean.TRUE;
} else if (aCol == 3) {
return event.getCategoryName();
} else if (aCol == 4) {
return event.getNDC();
}
return event.getMessage();
}
|
public boolean | isPaused()
synchronized (mLock) {
return mPaused;
}
|
private boolean | matchFilter(org.apache.log4j.chainsaw.EventDetails aEvent)Returns whether an event matches the filters.
if (aEvent.getPriority().isGreaterOrEqual(mPriorityFilter) &&
(aEvent.getThreadName().indexOf(mThreadFilter) >= 0) &&
(aEvent.getCategoryName().indexOf(mCategoryFilter) >= 0) &&
((mNDCFilter.length() == 0) ||
((aEvent.getNDC() != null) &&
(aEvent.getNDC().indexOf(mNDCFilter) >= 0))))
{
final String rm = aEvent.getMessage();
if (rm == null) {
// only match if we have not filtering in place
return (mMessageFilter.length() == 0);
} else {
return (rm.indexOf(mMessageFilter) >= 0);
}
}
return false; // by default not match
|
public void | setCategoryFilter(java.lang.String aStr)Set the filter for the category field.
synchronized (mLock) {
mCategoryFilter = aStr.trim();
updateFilteredEvents(false);
}
|
public void | setMessageFilter(java.lang.String aStr)Set the filter for the message field.
synchronized (mLock) {
mMessageFilter = aStr.trim();
updateFilteredEvents(false);
}
|
public void | setNDCFilter(java.lang.String aStr)Set the filter for the NDC field.
synchronized (mLock) {
mNDCFilter = aStr.trim();
updateFilteredEvents(false);
}
|
public void | setPriorityFilter(org.apache.log4j.Priority aPriority)Sets the priority to filter events on. Only events of equal or higher
property are now displayed.
synchronized (mLock) {
mPriorityFilter = aPriority;
updateFilteredEvents(false);
}
|
public void | setThreadFilter(java.lang.String aStr)Set the filter for the thread field.
synchronized (mLock) {
mThreadFilter = aStr.trim();
updateFilteredEvents(false);
}
|
public void | toggle()Toggle whether collecting events
synchronized (mLock) {
mPaused = !mPaused;
}
|
private void | updateFilteredEvents(boolean aInsertedToFront)Update the filtered events data structure.
final long start = System.currentTimeMillis();
final List filtered = new ArrayList();
final int size = mAllEvents.size();
final Iterator it = mAllEvents.iterator();
while (it.hasNext()) {
final EventDetails event = (EventDetails) it.next();
if (matchFilter(event)) {
filtered.add(event);
}
}
final EventDetails lastFirst = (mFilteredEvents.length == 0)
? null
: mFilteredEvents[0];
mFilteredEvents = (EventDetails[]) filtered.toArray(EMPTY_LIST);
if (aInsertedToFront && (lastFirst != null)) {
final int index = filtered.indexOf(lastFirst);
if (index < 1) {
LOG.warn("In strange state");
fireTableDataChanged();
} else {
fireTableRowsInserted(0, index - 1);
}
} else {
fireTableDataChanged();
}
final long end = System.currentTimeMillis();
LOG.debug("Total time [ms]: " + (end - start)
+ " in update, size: " + size);
|