1 package hudson.util; 2 3 import java.util.AbstractList ; 4 import java.util.List ; 5 import java.util.logging.Handler ; 6 import java.util.logging.LogRecord ; 7 8 13 public class RingBufferLogHandler extends Handler { 14 15 private int start = 0; 16 private final LogRecord [] records; 17 private int size = 0; 18 19 public RingBufferLogHandler() { 20 this(256); 21 } 22 23 public RingBufferLogHandler(int ringSize) { 24 records = new LogRecord [ringSize]; 25 } 26 27 public synchronized void publish(LogRecord record) { 28 int len = records.length; 29 records[(start+size)%len]=record; 30 if(size==len) { 31 start++; 32 } else { 33 size++; 34 } 35 } 36 37 43 public List <LogRecord > getView() { 44 return new AbstractList <LogRecord >() { 45 public LogRecord get(int index) { 46 return records[(start+(size-(index+1)))%records.length]; 48 } 49 50 public int size() { 51 return size; 52 } 53 }; 54 } 55 56 public void flush() {} 58 public void close() throws SecurityException {} 59 } 60 | Popular Tags |