1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.core.read;
11
12 import ch.qos.logback.core.AppenderBase;
13 import ch.qos.logback.core.helpers.CyclicBuffer;
14
15
16
17
18
19
20
21
22 public class CyclicBufferAppender<E> extends AppenderBase<E> {
23
24 CyclicBuffer<E> cb;
25 int maxSize = 512;
26
27 public void start() {
28 cb = new CyclicBuffer<E>(maxSize);
29 super.start();
30 }
31
32 public void stop() {
33 cb = null;
34 super.stop();
35 }
36
37 @Override
38 protected void append(E eventObject) {
39 if (!isStarted()) {
40 return;
41 }
42 cb.add(eventObject);
43 }
44
45 public int getLength() {
46 if (isStarted()) {
47 return cb.length();
48 } else {
49 return 0;
50 }
51 }
52
53 public Object get(int i) {
54 if (isStarted()) {
55 return cb.get(i);
56 } else {
57 return null;
58 }
59 }
60
61
62
63
64 public int getMaxSize() {
65 return maxSize;
66 }
67
68 public void setMaxSize(int maxSize) {
69 this.maxSize = maxSize;
70 }
71
72 }