Package list libslf4j-java / 9a08ff7
New upstream version 1.7.32 Emmanuel Bourg a month ago
19 changed file(s) with 299 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.31</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.31</version>
7 <version>1.7.32</version>
88 </parent>
99
1010 <modelVersion>4.0.0</modelVersion>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.31</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.31</version>
9 <version>1.7.32</version>
1010 </parent>
1111
1212
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.31</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.31</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.31</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.31</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.31</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.31</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.31</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.31</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.31</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.31</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.31</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.31</version>
9 <version>1.7.32</version>
1010 </parent>
1111
1212 <artifactId>slf4j-site</artifactId>