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