Package list libslf4j-java / upstream/1.7.29
New upstream version 1.7.29 Emmanuel Bourg 8 months ago
20 changed file(s) with 897 addition(s) and 302 deletion(s). Raw diff Collapse all Expand all
00 language: java
1
2 jdk:
3 - openjdk8
4
15 notifications:
26 email:
37 - notification@qos.ch
8
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>integration</artifactId>
44 <parent>
55 <groupId>org.slf4j</groupId>
66 <artifactId>slf4j-parent</artifactId>
7 <version>1.7.28</version>
7 <version>1.7.29</version>
88 </parent>
99
1010 <modelVersion>4.0.0</modelVersion>
1414 <name>JCL 1.2 implemented over SLF4J</name>
1515 <description>JCL 1.2 implemented over SLF4J</description>
1616 <url>http://www.slf4j.org</url>
17
18 <licenses>
19 <license>
20 <name>Apache License, Version 2.0</name>
21 <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
22 <distribution>repo</distribution>
23 </license>
24 </licenses>
1725
1826 <dependencies>
1927 <dependency>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>jul-to-slf4j</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>osgi-over-slf4j</artifactId>
55
66 <groupId>org.slf4j</groupId>
77 <artifactId>slf4j-parent</artifactId>
8 <version>1.7.28</version>
8 <version>1.7.29</version>
99
1010 <packaging>pom</packaging>
1111 <name>SLF4J</name>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-android</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-api</artifactId>
33
44 import org.slf4j.Logger;
55 import org.slf4j.Marker;
6 import org.slf4j.helpers.MessageFormatter;
67 import org.slf4j.helpers.SubstituteLogger;
78
9 /**
10 *
11 * This class is used to record events during the initialization phase of the
12 * underlying logging framework. It is called by {@link SubstituteLogger}.
13 *
14 *
15 * @author Ceki G&uumllc&uuml;
16 * @author Wessel van Norel
17 *
18 */
819 public class EventRecodingLogger implements Logger {
920
1021 String name;
1122 SubstituteLogger logger;
1223 Queue<SubstituteLoggingEvent> eventQueue;
24
25 // as an event recording logger we have no choice but to record all events
26 final static boolean RECORD_ALL_EVENTS = true;
1327
1428 public EventRecodingLogger(SubstituteLogger logger, Queue<SubstituteLoggingEvent> eventQueue) {
1529 this.logger = logger;
2135 return name;
2236 }
2337
24 private void recordEvent(Level level, String msg, Object[] args, Throwable throwable) {
25 recordEvent(level, null, msg, args, throwable);
26 }
27
38 public boolean isTraceEnabled() {
39 return RECORD_ALL_EVENTS;
40 }
41
42 public void trace(String msg) {
43 recordEvent_0Args(Level.TRACE, null, msg, null);
44 }
45
46 public void trace(String format, Object arg) {
47 recordEvent_1Args(Level.TRACE, null, format, arg);
48 }
49
50 public void trace(String format, Object arg1, Object arg2) {
51 recordEvent2Args(Level.TRACE, null, format, arg1, arg2);
52 }
53
54 public void trace(String format, Object... arguments) {
55 recordEventArgArray(Level.TRACE, null, format, arguments);
56 }
57
58 public void trace(String msg, Throwable t) {
59 recordEvent_0Args(Level.TRACE, null, msg, t);
60 }
61
62 public boolean isTraceEnabled(Marker marker) {
63 return RECORD_ALL_EVENTS;
64 }
65
66 public void trace(Marker marker, String msg) {
67 recordEvent_0Args(Level.TRACE, marker, msg, null);
68 }
69
70 public void trace(Marker marker, String format, Object arg) {
71 recordEvent_1Args(Level.TRACE, marker, format, arg);
72 }
73
74 public void trace(Marker marker, String format, Object arg1, Object arg2) {
75 recordEvent2Args(Level.TRACE, marker, format, arg1, arg2);
76 }
77
78 public void trace(Marker marker, String format, Object... argArray) {
79 recordEventArgArray(Level.TRACE, marker, format, argArray);
80 }
81
82 public void trace(Marker marker, String msg, Throwable t) {
83 recordEvent_0Args(Level.TRACE, marker, msg, t);
84 }
85
86 public boolean isDebugEnabled() {
87 return RECORD_ALL_EVENTS;
88 }
89
90 public void debug(String msg) {
91 recordEvent_0Args(Level.DEBUG, null, msg, null);
92 }
93
94 public void debug(String format, Object arg) {
95 recordEvent_1Args(Level.DEBUG, null, format, arg);
96 }
97
98 public void debug(String format, Object arg1, Object arg2) {
99 recordEvent2Args(Level.DEBUG, null, format, arg1, arg2);
100 }
101
102 public void debug(String format, Object... arguments) {
103 recordEventArgArray(Level.DEBUG, null, format, arguments);
104 }
105
106 public void debug(String msg, Throwable t) {
107 recordEvent_0Args(Level.DEBUG, null, msg, t);
108 }
109
110 public boolean isDebugEnabled(Marker marker) {
111 return RECORD_ALL_EVENTS;
112 }
113
114 public void debug(Marker marker, String msg) {
115 recordEvent_0Args(Level.DEBUG, marker, msg, null);
116 }
117
118 public void debug(Marker marker, String format, Object arg) {
119 recordEvent_1Args(Level.DEBUG, marker, format, arg);
120 }
121
122 public void debug(Marker marker, String format, Object arg1, Object arg2) {
123 recordEvent2Args(Level.DEBUG, marker, format, arg1, arg2);
124 }
125
126 public void debug(Marker marker, String format, Object... arguments) {
127 recordEventArgArray(Level.DEBUG, marker, format, arguments);
128 }
129
130 public void debug(Marker marker, String msg, Throwable t) {
131 recordEvent_0Args(Level.DEBUG, marker, msg, t);
132 }
133
134 public boolean isInfoEnabled() {
135 return RECORD_ALL_EVENTS;
136 }
137
138 public void info(String msg) {
139 recordEvent_0Args(Level.INFO, null, msg, null);
140 }
141
142 public void info(String format, Object arg) {
143 recordEvent_1Args(Level.INFO, null, format, arg);
144 }
145
146 public void info(String format, Object arg1, Object arg2) {
147 recordEvent2Args(Level.INFO, null, format, arg1, arg2);
148 }
149
150 public void info(String format, Object... arguments) {
151 recordEventArgArray(Level.INFO, null, format, arguments);
152 }
153
154 public void info(String msg, Throwable t) {
155 recordEvent_0Args(Level.INFO, null, msg, t);
156 }
157
158 public boolean isInfoEnabled(Marker marker) {
159 return RECORD_ALL_EVENTS;
160 }
161
162 public void info(Marker marker, String msg) {
163 recordEvent_0Args(Level.INFO, marker, msg, null);
164 }
165
166 public void info(Marker marker, String format, Object arg) {
167 recordEvent_1Args(Level.INFO, marker, format, arg);
168 }
169
170 public void info(Marker marker, String format, Object arg1, Object arg2) {
171 recordEvent2Args(Level.INFO, marker, format, arg1, arg2);
172 }
173
174 public void info(Marker marker, String format, Object... arguments) {
175 recordEventArgArray(Level.INFO, marker, format, arguments);
176 }
177
178 public void info(Marker marker, String msg, Throwable t) {
179 recordEvent_0Args(Level.INFO, marker, msg, t);
180
181 }
182
183 public boolean isWarnEnabled() {
184 return RECORD_ALL_EVENTS;
185 }
186
187 public void warn(String msg) {
188 recordEvent_0Args(Level.WARN, null, msg, null);
189 }
190
191 public void warn(String format, Object arg) {
192 recordEvent_1Args(Level.WARN, null, format, arg);
193 }
194
195 public void warn(String format, Object arg1, Object arg2) {
196 recordEvent2Args(Level.WARN, null, format, arg1, arg2);
197 }
198
199 public void warn(String format, Object... arguments) {
200 recordEventArgArray(Level.WARN, null, format, arguments);
201 }
202
203 public void warn(String msg, Throwable t) {
204 recordEvent_0Args(Level.WARN, null, msg, t);
205 }
206
207 public boolean isWarnEnabled(Marker marker) {
208 return RECORD_ALL_EVENTS;
209 }
210
211 public void warn(Marker marker, String msg) {
212 recordEvent_0Args(Level.WARN, marker, msg, null);
213 }
214
215 public void warn(Marker marker, String format, Object arg) {
216 recordEvent_1Args(Level.WARN, marker, format, arg);
217 }
218
219 public void warn(Marker marker, String format, Object arg1, Object arg2) {
220 recordEvent2Args(Level.WARN, marker, format, arg1, arg2);
221 }
222
223 public void warn(Marker marker, String format, Object... arguments) {
224 recordEventArgArray(Level.WARN, marker, format, arguments);
225 }
226
227 public void warn(Marker marker, String msg, Throwable t) {
228 recordEvent_0Args(Level.WARN, marker, msg, t);
229 }
230
231 public boolean isErrorEnabled() {
232 return RECORD_ALL_EVENTS;
233 }
234
235 public void error(String msg) {
236 recordEvent_0Args(Level.ERROR, null, msg, null);
237 }
238
239 public void error(String format, Object arg) {
240 recordEvent_1Args(Level.ERROR, null, format, arg);
241 }
242
243 public void error(String format, Object arg1, Object arg2) {
244 recordEvent2Args(Level.ERROR, null, format, arg1, arg2);
245 }
246
247 public void error(String format, Object... arguments) {
248 recordEventArgArray(Level.ERROR, null, format, arguments);
249 }
250
251 public void error(String msg, Throwable t) {
252 recordEvent_0Args(Level.ERROR, null, msg, t);
253 }
254
255 public boolean isErrorEnabled(Marker marker) {
256 return RECORD_ALL_EVENTS;
257 }
258
259 public void error(Marker marker, String msg) {
260 recordEvent_0Args(Level.ERROR, marker, msg, null);
261 }
262
263 public void error(Marker marker, String format, Object arg) {
264 recordEvent_1Args(Level.ERROR, marker, format, arg);
265 }
266
267 public void error(Marker marker, String format, Object arg1, Object arg2) {
268 recordEvent2Args(Level.ERROR, marker, format, arg1, arg2);
269 }
270
271 public void error(Marker marker, String format, Object... arguments) {
272 recordEventArgArray(Level.ERROR, marker, format, arguments);
273 }
274
275 public void error(Marker marker, String msg, Throwable t) {
276 recordEvent_0Args(Level.ERROR, marker, msg, t);
277 }
278
279 private void recordEvent_0Args(Level level, Marker marker, String msg, Throwable t) {
280 recordEvent(level, marker, msg, null, t);
281 }
282
283 private void recordEvent_1Args(Level level, Marker marker, String msg, Object arg1) {
284 recordEvent(level, marker, msg, new Object[] { arg1 }, null);
285 }
286
287 private void recordEvent2Args(Level level, Marker marker, String msg, Object arg1, Object arg2) {
288 if (arg2 instanceof Throwable) {
289 recordEvent(level, marker, msg, new Object[] { arg1 }, (Throwable) arg2);
290 } else {
291 recordEvent(level, marker, msg, new Object[] { arg1, arg2 }, null);
292 }
293 }
294
295 private void recordEventArgArray(Level level, Marker marker, String msg, Object[] args) {
296 Throwable throwableCandidate = MessageFormatter.getThrowableCandidate(args);
297 if (throwableCandidate != null) {
298 Object[] trimmedCopy = MessageFormatter.trimmedCopy(args);
299 recordEvent(level, marker, msg, trimmedCopy, throwableCandidate);
300 } else {
301 recordEvent(level, marker, msg, args, null);
302 }
303 }
304
305
306 // WARNING: this method assumes that any throwable is properly extracted
28307 private void recordEvent(Level level, Marker marker, String msg, Object[] args, Throwable throwable) {
29 // System.out.println("recording logger:"+name+", msg:"+msg);
30308 SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent();
31309 loggingEvent.setTimeStamp(System.currentTimeMillis());
32310 loggingEvent.setLevel(level);
34312 loggingEvent.setLoggerName(name);
35313 loggingEvent.setMarker(marker);
36314 loggingEvent.setMessage(msg);
315 loggingEvent.setThreadName(Thread.currentThread().getName());
316
37317 loggingEvent.setArgumentArray(args);
38318 loggingEvent.setThrowable(throwable);
39 loggingEvent.setThreadName(Thread.currentThread().getName());
319
40320 eventQueue.add(loggingEvent);
41321 }
42
43 public boolean isTraceEnabled() {
44 return true;
45 }
46
47 public void trace(String msg) {
48 recordEvent(Level.TRACE, msg, null, null);
49 }
50
51 public void trace(String format, Object arg) {
52 recordEvent(Level.TRACE, format, new Object[] { arg }, null);
53 }
54
55 public void trace(String format, Object arg1, Object arg2) {
56 recordEvent(Level.TRACE, format, new Object[] { arg1, arg2 }, null);
57 }
58
59 public void trace(String format, Object... arguments) {
60 recordEvent(Level.TRACE, format, arguments, null);
61 }
62
63 public void trace(String msg, Throwable t) {
64 recordEvent(Level.TRACE, msg, null, t);
65 }
66
67 public boolean isTraceEnabled(Marker marker) {
68 return true;
69 }
70
71 public void trace(Marker marker, String msg) {
72 recordEvent(Level.TRACE, marker, msg, null, null);
73
74 }
75
76 public void trace(Marker marker, String format, Object arg) {
77 recordEvent(Level.TRACE, marker, format, new Object[] { arg }, null);
78 }
79
80 public void trace(Marker marker, String format, Object arg1, Object arg2) {
81 recordEvent(Level.TRACE, marker, format, new Object[] { arg1, arg2 }, null);
82 }
83
84 public void trace(Marker marker, String format, Object... argArray) {
85 recordEvent(Level.TRACE, marker, format, argArray, null);
86
87 }
88
89 public void trace(Marker marker, String msg, Throwable t) {
90 recordEvent(Level.TRACE, marker, msg, null, t);
91 }
92
93 public boolean isDebugEnabled() {
94 return true;
95 }
96
97 public void debug(String msg) {
98 recordEvent(Level.DEBUG, msg, null, null);
99 }
100
101 public void debug(String format, Object arg) {
102 recordEvent(Level.DEBUG, format, new Object[] { arg }, null);
103
104 }
105
106 public void debug(String format, Object arg1, Object arg2) {
107 recordEvent(Level.DEBUG, format, new Object[] { arg1, arg2 }, null);
108
109 }
110
111 public void debug(String format, Object... arguments) {
112 recordEvent(Level.DEBUG, format, arguments, null);
113 }
114
115 public void debug(String msg, Throwable t) {
116 recordEvent(Level.DEBUG, msg, null, t);
117 }
118
119 public boolean isDebugEnabled(Marker marker) {
120 return true;
121 }
122
123 public void debug(Marker marker, String msg) {
124 recordEvent(Level.DEBUG, marker, msg, null, null);
125 }
126
127 public void debug(Marker marker, String format, Object arg) {
128 recordEvent(Level.DEBUG, marker, format, new Object[] { arg }, null);
129 }
130
131 public void debug(Marker marker, String format, Object arg1, Object arg2) {
132 recordEvent(Level.DEBUG, marker, format, new Object[] { arg1, arg2 }, null);
133 }
134
135 public void debug(Marker marker, String format, Object... arguments) {
136 recordEvent(Level.DEBUG, marker, format, arguments, null);
137 }
138
139 public void debug(Marker marker, String msg, Throwable t) {
140 recordEvent(Level.DEBUG, marker, msg, null, t);
141 }
142
143 public boolean isInfoEnabled() {
144 return true;
145 }
146
147 public void info(String msg) {
148 recordEvent(Level.INFO, msg, null, null);
149 }
150
151 public void info(String format, Object arg) {
152 recordEvent(Level.INFO, format, new Object[] { arg }, null);
153 }
154
155 public void info(String format, Object arg1, Object arg2) {
156 recordEvent(Level.INFO, format, new Object[] { arg1, arg2 }, null);
157 }
158
159 public void info(String format, Object... arguments) {
160 recordEvent(Level.INFO, format, arguments, null);
161 }
162
163 public void info(String msg, Throwable t) {
164 recordEvent(Level.INFO, msg, null, t);
165 }
166
167 public boolean isInfoEnabled(Marker marker) {
168 return true;
169 }
170
171 public void info(Marker marker, String msg) {
172 recordEvent(Level.INFO, marker, msg, null, null);
173 }
174
175 public void info(Marker marker, String format, Object arg) {
176 recordEvent(Level.INFO, marker, format, new Object[] { arg }, null);
177 }
178
179 public void info(Marker marker, String format, Object arg1, Object arg2) {
180 recordEvent(Level.INFO, marker, format, new Object[] { arg1, arg2 }, null);
181 }
182
183 public void info(Marker marker, String format, Object... arguments) {
184 recordEvent(Level.INFO, marker, format, arguments, null);
185 }
186
187 public void info(Marker marker, String msg, Throwable t) {
188 recordEvent(Level.INFO, marker, msg, null, t);
189
190 }
191
192 public boolean isWarnEnabled() {
193 return true;
194 }
195
196 public void warn(String msg) {
197 recordEvent(Level.WARN, msg, null, null);
198 }
199
200 public void warn(String format, Object arg) {
201 recordEvent(Level.WARN, format, new Object[] { arg }, null);
202
203 }
204
205 public void warn(String format, Object arg1, Object arg2) {
206 recordEvent(Level.WARN, format, new Object[] { arg1, arg2 }, null);
207 }
208
209 public void warn(String format, Object... arguments) {
210 recordEvent(Level.WARN, format, arguments, null);
211 }
212
213 public void warn(String msg, Throwable t) {
214 recordEvent(Level.WARN, msg, null, t);
215 }
216
217 public boolean isWarnEnabled(Marker marker) {
218 return true;
219 }
220
221 public void warn(Marker marker, String msg) {
222 recordEvent(Level.WARN, msg, null, null);
223 }
224
225 public void warn(Marker marker, String format, Object arg) {
226 recordEvent(Level.WARN, format, new Object[] { arg }, null);
227 }
228
229 public void warn(Marker marker, String format, Object arg1, Object arg2) {
230 recordEvent(Level.WARN, marker, format, new Object[] { arg1, arg2 }, null);
231
232 }
233
234 public void warn(Marker marker, String format, Object... arguments) {
235 recordEvent(Level.WARN, marker, format, arguments, null);
236 }
237
238 public void warn(Marker marker, String msg, Throwable t) {
239 recordEvent(Level.WARN, marker, msg, null, t);
240 }
241
242 public boolean isErrorEnabled() {
243 return true;
244 }
245
246 public void error(String msg) {
247 recordEvent(Level.ERROR, msg, null, null);
248 }
249
250 public void error(String format, Object arg) {
251 recordEvent(Level.ERROR, format, new Object[] { arg }, null);
252
253 }
254
255 public void error(String format, Object arg1, Object arg2) {
256 recordEvent(Level.ERROR, format, new Object[] { arg1, arg2 }, null);
257
258 }
259
260 public void error(String format, Object... arguments) {
261 recordEvent(Level.ERROR, format, arguments, null);
262
263 }
264
265 public void error(String msg, Throwable t) {
266 recordEvent(Level.ERROR, msg, null, t);
267 }
268
269 public boolean isErrorEnabled(Marker marker) {
270 return true;
271 }
272
273 public void error(Marker marker, String msg) {
274 recordEvent(Level.ERROR, marker, msg, null, null);
275
276 }
277
278 public void error(Marker marker, String format, Object arg) {
279 recordEvent(Level.ERROR, marker, format, new Object[] { arg }, null);
280
281 }
282
283 public void error(Marker marker, String format, Object arg1, Object arg2) {
284 recordEvent(Level.ERROR, marker, format, new Object[] { arg1, arg2 }, null);
285 }
286
287 public void error(Marker marker, String format, Object... arguments) {
288 recordEvent(Level.ERROR, marker, format, arguments, null);
289 }
290
291 public void error(Marker marker, String msg, Throwable t) {
292 recordEvent(Level.ERROR, marker, msg, null, t);
293 }
294
295322 }
151151 }
152152
153153
154 static final Throwable getThrowableCandidate(Object[] argArray) {
155 if (argArray == null || argArray.length == 0) {
156 return null;
157 }
158
159 final Object lastEntry = argArray[argArray.length - 1];
160 if (lastEntry instanceof Throwable) {
161 return (Throwable) lastEntry;
162 }
163 return null;
164 }
165
166154 final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray) {
167 Throwable throwableCandidate = getThrowableCandidate(argArray);
155 Throwable throwableCandidate = MessageFormatter.getThrowableCandidate(argArray);
168156 Object[] args = argArray;
169157 if (throwableCandidate != null) {
170 args = trimmedCopy(argArray);
158 args = MessageFormatter.trimmedCopy(argArray);
171159 }
172160 return arrayFormat(messagePattern, args, throwableCandidate);
173 }
174
175 private static Object[] trimmedCopy(Object[] argArray) {
176 if (argArray == null || argArray.length == 0) {
177 throw new IllegalStateException("non-sensical empty or null argument array");
178 }
179 final int trimemdLen = argArray.length - 1;
180 Object[] trimmed = new Object[trimemdLen];
181 System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
182 return trimmed;
183161 }
184162
185163 final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray, Throwable throwable) {
410388 sbuf.append(']');
411389 }
412390
391 /**
392 * Helper method to determine if an {@link Object} array contains a {@link Throwable} as last element
393 *
394 * @param argArray
395 * The arguments off which we want to know if it contains a {@link Throwable} as last element
396 * @return if the last {@link Object} in argArray is a {@link Throwable} this method will return it,
397 * otherwise it returns null
398 */
399 public static Throwable getThrowableCandidate(final Object[] argArray) {
400 if (argArray == null || argArray.length == 0) {
401 return null;
402 }
403
404 final Object lastEntry = argArray[argArray.length - 1];
405 if (lastEntry instanceof Throwable) {
406 return (Throwable) lastEntry;
407 }
408
409 return null;
410 }
411
412 /**
413 * Helper method to get all but the last element of an array
414 *
415 * @param argArray
416 * The arguments from which we want to remove the last element
417 *
418 * @return a copy of the array without the last element
419 */
420 public static Object[] trimmedCopy(final Object[] argArray) {
421 if (argArray == null || argArray.length == 0) {
422 throw new IllegalStateException("non-sensical empty or null argument array");
423 }
424
425 final int trimmedLen = argArray.length - 1;
426
427 Object[] trimmed = new Object[trimmedLen];
428
429 if (trimmedLen > 0) {
430 System.arraycopy(argArray, 0, trimmed, 0, trimmedLen);
431 }
432
433 return trimmed;
434 }
435
413436 }
0 package org.slf4j.event;
1
2 import org.junit.After;
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.slf4j.Marker;
6 import org.slf4j.helpers.BasicMarkerFactory;
7 import org.slf4j.helpers.SubstituteLogger;
8
9 import java.util.Queue;
10 import java.util.concurrent.LinkedBlockingQueue;
11
12 import static org.junit.Assert.*;
13
14 public class EventRecodingLoggerTest {
15 private Queue<SubstituteLoggingEvent> queue;
16 private EventRecodingLogger logger;
17 private String message;
18 private Object param1;
19 private Object param2;
20 private Object param3;
21 private Object[] oneParam;
22 private Object[] twoParams;
23 private Object[] threeParams;
24 private Throwable exception;
25 private Marker marker;
26
27 @Before
28 public void setUp() {
29 queue = new LinkedBlockingQueue<SubstituteLoggingEvent>();
30 logger = new EventRecodingLogger(new SubstituteLogger("testLogger", queue, true), queue);
31 message = "Test message with 3 parameters {} {} {} {}";
32 param1 = 1;
33 param2 = 2;
34 param3 = 3;
35 oneParam = new Object[] { param1 };
36 twoParams = new Object[] { param1, param2 };
37 threeParams = new Object[] { param1, param2, param3 };
38 exception = new IllegalStateException("We just need an exception");
39 marker = new BasicMarkerFactory().getMarker("testMarker");
40 }
41
42 @After
43 public void tearDown() {
44 assertTrue(queue.isEmpty());
45 }
46
47 @Test
48 public void singleMessage() {
49 for (Level level : Level.values()) {
50 singleMessageCheck(level);
51 }
52 }
53
54 private void singleMessageCheck(Level level) {
55 switch (level) {
56 case TRACE:
57 logger.trace(message);
58 break;
59 case DEBUG:
60 logger.debug(message);
61 break;
62 case INFO:
63 logger.info(message);
64 break;
65 case WARN:
66 logger.warn(message);
67 break;
68 case ERROR:
69 logger.error(message);
70 break;
71 }
72 verifyMessageWithoutMarker(level, null, null);
73 }
74
75 @Test
76 public void oneParameter() {
77 for (Level level : Level.values()) {
78 oneParameterCheck(level);
79 }
80 }
81 private void oneParameterCheck(Level level) {
82 switch (level) {
83 case TRACE:
84 logger.trace(message, param1);
85 break;
86 case DEBUG:
87 logger.debug(message, param1);
88 break;
89 case INFO:
90 logger.info(message, param1);
91 break;
92 case WARN:
93 logger.warn(message, param1);
94 break;
95 case ERROR:
96 logger.error(message, param1);
97 break;
98 }
99 verifyMessageWithoutMarker(level, oneParam, null);
100 }
101
102 @Test
103 public void messageTwoParameters() {
104 for (Level level : Level.values()) {
105 messageTwoParametersCheck(level);
106 }
107 }
108
109 private void messageTwoParametersCheck(Level level) {
110 switch (level) {
111 case TRACE:
112 logger.trace(message, param1, param2);
113 break;
114 case DEBUG:
115 logger.debug(message, param1, param2);
116 break;
117 case INFO:
118 logger.info(message, param1, param2);
119 break;
120 case WARN:
121 logger.warn(message, param1, param2);
122 break;
123 case ERROR:
124 logger.error(message, param1, param2);
125 break;
126 }
127 verifyMessageWithoutMarker(level, twoParams, null);
128 }
129
130 @Test
131 public void traceMessageThreeParameters() {
132 for (Level level : Level.values()) {
133 threeParameterCheck(level);
134 }
135 }
136
137 private void threeParameterCheck(Level level) {
138 switch (level) {
139 case TRACE:
140 logger.trace(message, param1, param2, param3);
141 break;
142 case DEBUG:
143 logger.debug(message, param1, param2, param3);
144 break;
145 case INFO:
146 logger.info(message, param1, param2, param3);
147 break;
148 case WARN:
149 logger.warn(message, param1, param2, param3);
150 break;
151 case ERROR:
152 logger.error(message, param1, param2, param3);
153 break;
154 }
155 verifyMessageWithoutMarker(level, threeParams, null);
156 }
157
158 @Test
159 public void testMessageThrowable() {
160 for (Level level : Level.values()) {
161 throwableCheck(level);
162 }
163 }
164
165 private void throwableCheck(Level level) {
166 switch (level) {
167 case TRACE:
168 logger.trace(message, exception);
169 break;
170 case DEBUG:
171 logger.debug(message, exception);
172 break;
173 case INFO:
174 logger.info(message, exception);
175 break;
176 case WARN:
177 logger.warn(message, exception);
178 break;
179 case ERROR:
180 logger.error(message, exception);
181 break;
182 }
183 verifyMessageWithoutMarker(level, null, exception);
184 }
185
186 @Test
187 public void traceMessageOneParameterThrowable() {
188 for (Level level : Level.values()) {
189 oneParamThrowableCheck(level);
190 }
191 }
192
193 private void oneParamThrowableCheck(Level level) {
194 switch (level) {
195 case TRACE:
196 logger.trace(message, param1, exception);
197 break;
198 case DEBUG:
199 logger.debug(message, param1, exception);
200 break;
201 case INFO:
202 logger.info(message, param1, exception);
203 break;
204 case WARN:
205 logger.warn(message, param1, exception);
206 break;
207 case ERROR:
208 logger.error(message, param1, exception);
209 break;
210 }
211 verifyMessageWithoutMarker(level, oneParam, exception);
212 }
213
214 @Test
215 public void traceMessageTwoParametersThrowable() {
216 for (Level level : Level.values()) {
217 twoParamThrowableCheck(level);
218 }
219 }
220
221 private void twoParamThrowableCheck(Level level) {
222 switch (level) {
223 case TRACE:
224 logger.trace(message, param1, param2, exception);
225 break;
226 case DEBUG:
227 logger.debug(message, param1, param2, exception);
228 break;
229 case INFO:
230 logger.info(message, param1, param2, exception);
231 break;
232 case WARN:
233 logger.warn(message, param1, param2, exception);
234 break;
235 case ERROR:
236 logger.error(message, param1, param2, exception);
237 break;
238 }
239 verifyMessageWithoutMarker(level, twoParams, exception);
240 }
241
242 @Test
243 public void testMessageThreeParametersThrowable() {
244 for (Level level : Level.values()) {
245 messageWith3ArgsPlusException(level);
246 }
247 }
248
249 private void messageWith3ArgsPlusException(Level level) {
250 switch (level) {
251 case TRACE:
252 logger.trace(message, param1, param2, param3, exception);
253 break;
254 case DEBUG:
255 logger.debug(message, param1, param2, param3, exception);
256 break;
257 case INFO:
258 logger.info(message, param1, param2, param3, exception);
259 break;
260 case WARN:
261 logger.warn(message, param1, param2, param3, exception);
262 break;
263 case ERROR:
264 logger.error(message, param1, param2, param3, exception);
265 break;
266 }
267 verifyMessageWithoutMarker(level, threeParams, exception);
268 }
269
270 @Test
271 public void markerMessage() {
272 for (Level level : Level.values()) {
273 markerMessageCheck(level);
274 }
275 }
276 private void markerMessageCheck(Level level) {
277 switch (level) {
278 case TRACE:
279 logger.trace(marker, message);
280 break;
281 case DEBUG:
282 logger.debug(marker, message);
283 break;
284 case INFO:
285 logger.info(marker, message);
286 break;
287 case WARN:
288 logger.warn(marker, message);
289 break;
290 case ERROR:
291 logger.error(marker, message);
292 break;
293 }
294 verifyMessage(level, marker, null, null);
295 }
296
297 @Test
298 public void markerMessageOneParameter() {
299 for (Level level : Level.values()) {
300 markerMessageOneParameter(level);
301 }
302 }
303 private void markerMessageOneParameter(Level level) {
304 switch (level) {
305 case TRACE:
306 logger.trace(marker, message, param1);
307 break;
308 case DEBUG:
309 logger.debug(marker, message, param1);
310 break;
311 case INFO:
312 logger.info(marker, message, param1);
313 break;
314 case WARN:
315 logger.warn(marker, message, param1);
316 break;
317 case ERROR:
318 logger.error(marker, message, param1);
319 break;
320 }
321 verifyMessage(level, marker, oneParam, null);
322 }
323
324 @Test
325 public void traceMarkerMessageTwoParameters() {
326 for (Level level : Level.values()) {
327 markerMessageTwoParameters(level);
328 }
329 }
330
331 private void markerMessageTwoParameters(Level level) {
332 switch (level) {
333 case TRACE:
334 logger.trace(marker, message, param1, param2);
335 break;
336 case DEBUG:
337 logger.debug(marker, message, param1, param2);
338 break;
339 case INFO:
340 logger.info(marker, message, param1, param2);
341 break;
342 case WARN:
343 logger.warn(marker, message, param1, param2);
344 break;
345 case ERROR:
346 logger.error(marker, message, param1, param2);
347 break;
348 }
349 verifyMessage(level, marker, twoParams, null);
350 }
351
352 @Test
353 public void traceMarkerMessageThreeParameters() {
354 for (Level level : Level.values()) {
355 markerMessageThreeParameters(level);
356 }
357 }
358
359 private void markerMessageThreeParameters(Level level) {
360 switch (level) {
361 case TRACE:
362 logger.trace(marker, message, param1, param2, param3);
363 break;
364 case DEBUG:
365 logger.debug(marker, message, param1, param2, param3);
366 break;
367 case INFO:
368 logger.info(marker, message, param1, param2, param3);
369 break;
370 case WARN:
371 logger.warn(marker, message, param1, param2, param3);
372 break;
373 case ERROR:
374 logger.error(marker, message, param1, param2, param3);
375 break;
376 }
377 verifyMessage(level, marker, threeParams, null);
378 }
379
380 @Test
381 public void markerMessageThrowable() {
382 for (Level level : Level.values()) {
383 markerMessageThrowable(level);
384 }
385 }
386
387 private void markerMessageThrowable(Level level) {
388 switch (level) {
389 case TRACE:
390 logger.trace(marker, message, exception);
391 break;
392 case DEBUG:
393 logger.debug(marker, message, exception);
394 break;
395 case INFO:
396 logger.info(marker, message, exception);
397 break;
398 case WARN:
399 logger.warn(marker, message, exception);
400 break;
401 case ERROR:
402 logger.error(marker, message, exception);
403 break;
404 }
405 verifyMessage(level, marker, null, exception);
406 }
407
408 @Test
409 public void markerMessageOneParameterThrowable() {
410 for (Level level : Level.values()) {
411 markerMessageOneParameterThrowableCheck(level);
412 }
413 }
414
415 private void markerMessageOneParameterThrowableCheck(Level level) {
416 switch (level) {
417 case TRACE:
418 logger.trace(marker, message, param1, exception);
419 break;
420 case DEBUG:
421 logger.debug(marker, message, param1, exception);
422 break;
423 case INFO:
424 logger.info(marker, message, param1, exception);
425 break;
426 case WARN:
427 logger.warn(marker, message, param1, exception);
428 break;
429 case ERROR:
430 logger.error(marker, message, param1, exception);
431 break;
432 }
433 verifyMessage(level, marker, oneParam, exception);
434 }
435
436 @Test
437 public void traceMarkerMessageTwoParametersThrowable() {
438 for (Level level : Level.values()) {
439 markerMessageTwoParametersThrowableCheck(level);
440 }
441 }
442
443 private void markerMessageTwoParametersThrowableCheck(Level level) {
444 switch (level) {
445 case TRACE:
446 logger.trace(marker, message, param1, param2, exception);
447 break;
448 case DEBUG:
449 logger.debug(marker, message, param1, param2, exception);
450 break;
451 case INFO:
452 logger.info(marker, message, param1, param2, exception);
453 break;
454 case WARN:
455 logger.warn(marker, message, param1, param2, exception);
456 break;
457 case ERROR:
458 logger.error(marker, message, param1, param2, exception);
459 break;
460 }
461 verifyMessage(level, marker, twoParams, exception);
462 }
463
464 @Test
465 public void traceMarkerMessageThreeParametersThrowable() {
466 for (Level level : Level.values()) {
467 markerMessageThreeParametersThrowableCheck(level);
468 }
469 }
470
471 private void markerMessageThreeParametersThrowableCheck(Level level) {
472 switch (level) {
473 case TRACE:
474 logger.trace(marker, message, param1, param2, param3, exception);
475 break;
476 case DEBUG:
477 logger.debug(marker, message, param1, param2, param3, exception);
478 break;
479 case INFO:
480 logger.info(marker, message, param1, param2, param3, exception);
481 break;
482 case WARN:
483 logger.warn(marker, message, param1, param2, param3, exception);
484 break;
485 case ERROR:
486 logger.error(marker, message, param1, param2, param3, exception);
487 break;
488 }
489 verifyMessage(level, marker, threeParams, exception);
490 }
491
492 private void verifyMessageWithoutMarker(Level level, Object[] arguments, Throwable exception) {
493 verifyMessage(level, null, arguments, exception);
494 }
495
496 private void verifyMessage(Level level, Marker marker, Object[] arguments, Throwable exception) {
497
498 assertEquals("missing event: ", 1, queue.size());
499 SubstituteLoggingEvent event = queue.poll();
500 assertNotNull(event);
501
502 if (marker == null) {
503 assertNull(event.getMarker());
504 } else {
505 assertEquals(marker, event.getMarker());
506 }
507
508 assertEquals(message, event.getMessage());
509
510 if (arguments == null) {
511 assertNull(event.getArgumentArray());
512 } else {
513 assertArrayEquals(arguments, event.getArgumentArray());
514 }
515
516 assertEquals("wrong level: ", level, event.getLevel());
517
518 if (exception == null) {
519 assertNull(event.getThrowable());
520 } else {
521 assertEquals(exception, event.getThrowable());
522 }
523 }
524 }
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-ext</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-jcl</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-jdk14</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-log4j12</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-migrator</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-nop</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-simple</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.28</version>
9 <version>1.7.29</version>
1010 </parent>
1111
1212 <artifactId>slf4j-site</artifactId>
3030 </resources>
3131 <plugins>
3232
33
34 <plugin>
35 <groupId>org.apache.maven.plugins</groupId>
36 <artifactId>maven-deploy-plugin</artifactId>
37 <configuration>
38 <skip>true</skip>
39 </configuration>
40 </plugin>
41
42
3343 <plugin>
3444 <groupId>org.apache.maven.plugins</groupId>
3545 <artifactId>maven-source-plugin</artifactId>
3949 <include>**/META-INF/*</include>
4050 </includes>
4151
42 <excludes>
43 <exclude>x**</exclude>
44 </excludes>
4552 </configuration>
4653 <executions>
4754 <execution>