1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j;
18
19 import org.apache.log4j.spi.ErrorHandler;
20 import org.apache.log4j.spi.Filter;
21 import org.apache.log4j.spi.LoggingEvent;
22 import org.apache.log4j.spi.OptionHandler;
23
24
25
26
27 public abstract class AppenderSkeleton implements Appender, OptionHandler {
28
29 protected Layout layout;
30
31 protected String name;
32
33 protected Priority threshold;
34
35 protected ErrorHandler errorHandler = new NoOpErrorHandler();
36
37 protected Filter headFilter;
38
39 protected Filter tailFilter;
40
41 protected boolean closed = false;
42
43
44
45
46 public AppenderSkeleton() {
47 super();
48 }
49
50 protected AppenderSkeleton(final boolean isActive) {
51 super();
52 }
53
54 @Override
55 public void activateOptions() {
56 }
57
58 @Override
59 public void addFilter(final Filter newFilter) {
60 if(headFilter == null) {
61 headFilter = tailFilter = newFilter;
62 } else {
63 tailFilter.setNext(newFilter);
64 tailFilter = newFilter;
65 }
66 }
67
68 protected abstract void append(LoggingEvent event);
69
70 @Override
71 public void clearFilters() {
72 headFilter = tailFilter = null;
73 }
74
75 @Override
76 public void finalize() {
77 }
78
79 @Override
80 public ErrorHandler getErrorHandler() {
81 return this.errorHandler;
82 }
83
84 @Override
85 public Filter getFilter() {
86 return headFilter;
87 }
88
89 public final Filter getFirstFilter() {
90 return headFilter;
91 }
92
93 @Override
94 public Layout getLayout() {
95 return layout;
96 }
97
98 @Override
99 public final String getName() {
100 return this.name;
101 }
102
103 public Priority getThreshold() {
104 return threshold;
105 }
106
107 public boolean isAsSevereAsThreshold(final Priority priority) {
108 return ((threshold == null) || priority.isGreaterOrEqual(threshold));
109 }
110
111
112
113
114
115 @Override
116 public void doAppend(final LoggingEvent event) {
117 }
118
119
120
121
122
123
124 @Override
125 public synchronized void setErrorHandler(final ErrorHandler eh) {
126 if (eh != null) {
127 this.errorHandler = eh;
128 }
129 }
130
131 @Override
132 public void setLayout(final Layout layout) {
133 this.layout = layout;
134 }
135
136 @Override
137 public void setName(final String name) {
138 this.name = name;
139 }
140
141 public void setThreshold(final Priority threshold) {
142 this.threshold = threshold;
143 }
144
145 public static class NoOpErrorHandler implements ErrorHandler {
146 @Override
147 public void setLogger(final Logger logger) {
148
149 }
150
151 @Override
152 public void error(final String message, final Exception e, final int errorCode) {
153
154 }
155
156 @Override
157 public void error(final String message) {
158
159 }
160
161 @Override
162 public void error(final String message, final Exception e, final int errorCode, final LoggingEvent event) {
163
164 }
165
166 @Override
167 public void setAppender(final Appender appender) {
168
169 }
170
171 @Override
172 public void setBackupAppender(final Appender appender) {
173
174 }
175 }
176 }