01: package dalma.webui;
02:
03: import java.util.ArrayList;
04: import java.util.LinkedList;
05: import java.util.List;
06: import java.util.logging.Handler;
07: import java.util.logging.LogRecord;
08:
09: /**
10: * {@link Handler} that simply buffers {@link LogRecord}.
11: *
12: * @author Kohsuke Kawaguchi
13: */
14: public class LogRecorder extends Handler {
15: private final List<LogRecord> buf = new LinkedList<LogRecord>();
16: private static final int MAX = 100;
17:
18: public synchronized List<LogRecord> getLogRecords() {
19: // need to copy to avoid synchronization issue
20: return new ArrayList<LogRecord>(buf);
21: }
22:
23: public synchronized void publish(LogRecord record) {
24: buf.add(0, record);
25: if (buf.size() > MAX)
26: buf.remove(buf.size() - 1);
27: }
28:
29: public void flush() {
30: // noop
31: }
32:
33: public void close() throws SecurityException {
34: // noop
35: }
36: }
|