Package list libslf4j-java / e3f9d7c
Import upstream version 1.7.32 Debian Janitor 3 months ago
22 changed file(s) with 400 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.30</version>
9 <version>1.7.32</version>
1010 </parent>
1111
1212 <artifactId>integration</artifactId>
44 <parent>
55 <groupId>org.slf4j</groupId>
66 <artifactId>slf4j-parent</artifactId>
7 <version>1.7.30</version>
7 <version>1.7.32</version>
88 </parent>
99
1010 <modelVersion>4.0.0</modelVersion>
103103 * the message to log. Converted to {@link String}
104104 */
105105 public void trace(Object message) {
106 logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, null);
106 if (isTraceEnabled()) {
107 logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, null);
108 }
107109 }
108110
109111 /**
116118 * the exception to log
117119 */
118120 public void trace(Object message, Throwable t) {
119 logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, t);
121 if (isTraceEnabled()) {
122 logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, t);
123 }
120124 }
121125
122126 /**
127131 * the message to log. Converted to {@link String}
128132 */
129133 public void debug(Object message) {
130 logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, null);
134 if (isDebugEnabled()) {
135 logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, null);
136 }
131137 }
132138
133139 /**
140146 * the exception to log
141147 */
142148 public void debug(Object message, Throwable t) {
143 logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, t);
149 if (isDebugEnabled()) {
150 logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, t);
151 }
144152 }
145153
146154 /**
151159 * the message to log. Converted to {@link String}
152160 */
153161 public void info(Object message) {
154 logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, null);
162 if (isInfoEnabled()) {
163 logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, null);
164 }
155165 }
156166
157167 /**
164174 * the exception to log
165175 */
166176 public void info(Object message, Throwable t) {
167 logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, t);
177 if (isInfoEnabled()) {
178 logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, t);
179 }
168180 }
169181
170182 /**
175187 * the message to log. Converted to {@link String}
176188 */
177189 public void warn(Object message) {
178 logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, null);
190 if (isWarnEnabled()) {
191 logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, null);
192 }
179193 }
180194
181195 /**
188202 * the exception to log
189203 */
190204 public void warn(Object message, Throwable t) {
191 logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, t);
205 if (isWarnEnabled()) {
206 logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, t);
207 }
192208 }
193209
194210 /**
199215 * the message to log. Converted to {@link String}
200216 */
201217 public void error(Object message) {
202 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null);
218 if (isErrorEnabled()) {
219 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null);
220 }
203221 }
204222
205223 /**
212230 * the exception to log
213231 */
214232 public void error(Object message, Throwable t) {
215 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t);
233 if (isErrorEnabled()) {
234 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t);
235 }
216236 }
217237
218238 /**
223243 * the message to log. Converted to {@link String}
224244 */
225245 public void fatal(Object message) {
226 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null);
246 if (isErrorEnabled()) {
247 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null);
248 }
227249 }
228250
229251 /**
236258 * the exception to log
237259 */
238260 public void fatal(Object message, Throwable t) {
239 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t);
261 if (isErrorEnabled()) {
262 logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t);
263 }
240264 }
241265
242266 /**
2626
2727 import static org.junit.Assert.assertFalse;
2828 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.assertEquals;
2930
3031 import org.junit.Test;
3132
8485 log.fatal(null, e);
8586 log.fatal("fatal message", e);
8687 }
88
89 @Test
90 public void testAvoidConvertingObjectToString() {
91 Log log = LogFactory.getLog(InvokeJCLTest.class);
92 Exception e = new Exception("just testing");
93
94 TestMessage fatalMsg = new TestMessage("fatal msg");
95 TestMessage errorMsg = new TestMessage("error msg");
96 TestMessage warnMsg = new TestMessage("warn msg");
97 TestMessage infoMsg = new TestMessage("info msg");
98 TestMessage debugMsg = new TestMessage("debug msg");
99 TestMessage traceMsg = new TestMessage("trace msg");
100
101 log.fatal(fatalMsg);
102 log.fatal(fatalMsg, e);
103 assertEquals(2, fatalMsg.invokedCount);
104
105 log.error(errorMsg);
106 log.error(errorMsg, e);
107 assertEquals(2, errorMsg.invokedCount);
108
109 log.warn(warnMsg);
110 log.warn(warnMsg, e);
111 assertEquals(2, warnMsg.invokedCount);
112
113 log.info(infoMsg);
114 log.info(infoMsg, e);
115 assertEquals(2, infoMsg.invokedCount);
116
117 log.debug(debugMsg);
118 log.debug(debugMsg, e);
119 assertEquals(0, debugMsg.invokedCount);
120
121 log.trace(traceMsg);
122 log.trace(traceMsg, e);
123 assertEquals(0, traceMsg.invokedCount);
124 }
125
126 static class TestMessage {
127
128 private final String msg;
129 int invokedCount = 0;
130
131 TestMessage(String msg) {this.msg = msg;}
132
133 @Override
134 public String toString() {
135 invokedCount++;
136 return msg;
137 }
138 }
139
87140 }
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</version>
1010 </parent>
1111
1212
1414 */
1515 package org.apache.log4j;
1616
17 /**
18 * Skeleton implementation of ConsoleAppender
19 */
1720 public class ConsoleAppender extends WriterAppender {
1821
22 public ConsoleAppender() {
23 }
24
25 public ConsoleAppender(Layout layout) {
26 }
27
28 public ConsoleAppender(Layout layout, String target) {
29 }
30
1931 }
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.30</version>
9 <version>1.7.32</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.30</version>
8 <version>1.7.32</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.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</version>
1010 </parent>
1111
1212 <artifactId>slf4j-api</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</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.30</version>
9 <version>1.7.32</version>
1010 </parent>
1111
1212 <artifactId>slf4j-simple</artifactId>
156156 protected static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10;
157157
158158 private static boolean INITIALIZED = false;
159 static SimpleLoggerConfiguration CONFIG_PARAMS = null;
159 static final private SimpleLoggerConfiguration CONFIG_PARAMS = new SimpleLoggerConfiguration();
160160
161161 static void lazyInit() {
162162 if (INITIALIZED) {
169169 // external software might be invoking this method directly. Do not rename
170170 // or change its semantics.
171171 static void init() {
172 CONFIG_PARAMS = new SimpleLoggerConfiguration();
173172 CONFIG_PARAMS.init();
174173 }
175174
311310 throw new IllegalStateException("Unrecognized level [" + level + "]");
312311 }
313312
313 /**
314 * To avoid intermingling of log messages and associated stack traces, the two
315 * operations are done in a synchronized block.
316 *
317 * @param buf
318 * @param t
319 */
314320 void write(StringBuilder buf, Throwable t) {
315321 PrintStream targetStream = CONFIG_PARAMS.outputChoice.getTargetPrintStream();
316322
317 targetStream.println(buf.toString());
318 writeThrowable(t, targetStream);
319 targetStream.flush();
323 synchronized (CONFIG_PARAMS) {
324 targetStream.println(buf.toString());
325 writeThrowable(t, targetStream);
326 targetStream.flush();
327 }
328
320329 }
321330
322331 protected void writeThrowable(Throwable t, PrintStream targetStream) {
0 /**
1 * Copyright (c) 2004-2021 QOS.ch
2 * All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24 package org.slf4j.simple.multiThreadedExecution;
25
26 import java.io.PrintStream;
27
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35 * Tests that output in multi-threaded environments is not mingled.
36 *
37 * See also https://jira.qos.ch/browse/SLF4J-515
38 */
39 public class MultithereadedExecutionTest {
40
41 private static int THREAD_COUNT = 2;
42 private static long TEST_DURATION_IN_MILLIS = 100;
43
44 private Thread[] threads = new Thread[THREAD_COUNT];
45
46 private final PrintStream oldOut = System.out;
47 StateCheckingPrintStream scps = new StateCheckingPrintStream(oldOut);
48
49 volatile boolean signal = false;
50
51 @Before
52 public void setup() {
53 System.setErr(scps);
54 // System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.err");
55 // LoggerFactoryFriend.reset();
56 }
57
58 @After
59 public void tearDown() throws Exception {
60 // LoggerFactoryFriend.reset();
61 // System.clearProperty(SimpleLogger.LOG_FILE_KEY);
62 System.setErr(oldOut);
63 }
64
65 @Test
66 public void test() throws Throwable {
67 WithException withException = new WithException();
68 Other other = new Other();
69 threads[0] = new Thread(withException);
70 threads[1] = new Thread(other);
71 threads[0].start();
72 threads[1].start();
73 Thread.sleep(TEST_DURATION_IN_MILLIS);
74 signal = true;
75 threads[0].join();
76 threads[1].join();
77
78 if (withException.throwable != null) {
79 throw withException.throwable;
80 }
81
82 if (other.throwable != null) {
83 throw other.throwable;
84 }
85
86 }
87
88 class WithException implements Runnable {
89
90 volatile Throwable throwable;
91 Logger logger = LoggerFactory.getLogger(WithException.class);
92
93 public void run() {
94 int i = 0;
95
96 while (!signal) {
97 try {
98 logger.info("Hello {}", i, new Throwable("i=" + i));
99 i++;
100 } catch (Throwable t) {
101 throwable = t;
102 MultithereadedExecutionTest.this.signal = true;
103 return;
104 }
105 }
106
107 }
108 }
109
110 class Other implements Runnable {
111 volatile Throwable throwable;
112 Logger logger = LoggerFactory.getLogger(Other.class);
113
114 public void run() {
115 int i = 0;
116 while (!signal) {
117 try {
118 logger.info("Other {}", i++);
119 } catch (Throwable t) {
120 throwable = t;
121 MultithereadedExecutionTest.this.signal = true;
122 return;
123 }
124 }
125 }
126 }
127 }
0 /**
1 * Copyright (c) 2004-2021 QOS.ch
2 * All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24 package org.slf4j.simple.multiThreadedExecution;
25
26 import java.io.PrintStream;
27 import java.util.regex.Pattern;
28
29 /**
30 * This PrintStream checks that output lines are in an expected order.
31 *
32 * @author ceki
33 */
34 public class StateCheckingPrintStream extends PrintStream {
35
36 enum State {
37 INITIAL, UNKNOWN, HELLO, THROWABLE, AT1, AT2, OTHER;
38 }
39
40 volatile State currentState = State.INITIAL;
41
42 public StateCheckingPrintStream(PrintStream ps) {
43 super(ps);
44 }
45
46 public void print(String s) {
47 }
48
49 public void println(String s) {
50
51 State next = computeState(s);
52 //System.out.println(next + " " + s);
53 switch (currentState) {
54 case INITIAL:
55 currentState = next;
56 break;
57
58 case UNKNOWN:
59 // ignore garbage
60 currentState = next;
61 break;
62
63 case OTHER:
64 if (next == State.UNKNOWN) {
65 currentState = State.UNKNOWN;
66 return;
67 }
68
69 if (next != State.OTHER && next != State.HELLO) {
70 throw badState(s, currentState, next);
71 }
72 currentState = next;
73 break;
74
75 case HELLO:
76 if (next != State.THROWABLE) {
77 throw badState(s, currentState, next);
78 }
79 currentState = next;
80 break;
81 case THROWABLE:
82 if (next != State.AT1) {
83 throw badState(s, currentState, next);
84 }
85 currentState = next;
86 break;
87
88 case AT1:
89 if (next != State.AT2) {
90 throw badState(s, currentState, next);
91 }
92 currentState = next;
93 break;
94
95 case AT2:
96 currentState = next;
97 break;
98 default:
99 throw new IllegalStateException("Unreachable code");
100 }
101 }
102
103 private IllegalStateException badState(String s, State currentState2, State next) {
104 return new IllegalStateException("Unexpected state " + next + " for current state " + currentState2 + " for " + s);
105
106 }
107
108 String OTHER_PATTERN_STR = ".*Other \\d{1,5}";
109 String HELLO_PATTERN_STR = ".*Hello \\d{1,5}";
110 String THROWABLE_PATTERN_STR = "java.lang.Throwable: i=\\d{1,5}";
111 String AT1_PATTERN_STR = "\\s*at " + this.getClass().getPackage().getName() + ".*";
112 String AT2_PATTERN_STR = "\\s*at " + ".*Thread.java.*";
113
114 Pattern PATTERN_OTHER = Pattern.compile(OTHER_PATTERN_STR);
115 Pattern PATTERN_HELLO = Pattern.compile(HELLO_PATTERN_STR);
116 Pattern PATTERN_THROWABLE = Pattern.compile(THROWABLE_PATTERN_STR);
117 Pattern PATTERN_AT1 = Pattern.compile(AT1_PATTERN_STR);
118 Pattern PATTERN_AT2 = Pattern.compile(AT2_PATTERN_STR);
119
120 private State computeState(String s) {
121
122 if (PATTERN_OTHER.matcher(s).matches()) {
123 return State.OTHER;
124 } else if (PATTERN_HELLO.matcher(s).matches()) {
125 return State.HELLO;
126 } else if (PATTERN_THROWABLE.matcher(s).matches()) {
127 return State.THROWABLE;
128 } else if (PATTERN_AT1.matcher(s).matches()) {
129 return State.AT1;
130 } else if (PATTERN_AT2.matcher(s).matches()) {
131 return State.AT2;
132 } else {
133 return State.UNKNOWN;
134 }
135 }
136
137 public void println(Object o) {
138 println(o.toString());
139 }
140 }
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.30</version>
9 <version>1.7.32</version>
1010 </parent>
1111
1212 <artifactId>slf4j-site</artifactId>