Skip to content

Commit 1c6cbf0

Browse files
committed
Merge branch 'master' of github.com:qos-ch/slf4j
2 parents 19bfd0f + c246302 commit 1c6cbf0

File tree

27 files changed

+309
-220
lines changed

27 files changed

+309
-220
lines changed

integration/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.slf4j</groupId>
99
<artifactId>slf4j-parent</artifactId>
10-
<version>1.7.21-SNAPSHOT</version>
10+
<version>1.7.22-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>integration</artifactId>

jcl-over-slf4j/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.slf4j</groupId>
77
<artifactId>slf4j-parent</artifactId>
8-
<version>1.7.21-SNAPSHOT</version>
8+
<version>1.7.22-SNAPSHOT</version>
99
</parent>
1010

1111
<modelVersion>4.0.0</modelVersion>

jul-to-slf4j/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.slf4j</groupId>
99
<artifactId>slf4j-parent</artifactId>
10-
<version>1.7.21-SNAPSHOT</version>
10+
<version>1.7.22-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>jul-to-slf4j</artifactId>

log4j-over-slf4j/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.slf4j</groupId>
99
<artifactId>slf4j-parent</artifactId>
10-
<version>1.7.21-SNAPSHOT</version>
10+
<version>1.7.22-SNAPSHOT</version>
1111
</parent>
1212

1313

osgi-over-slf4j/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.slf4j</groupId>
99
<artifactId>slf4j-parent</artifactId>
10-
<version>1.7.21-SNAPSHOT</version>
10+
<version>1.7.22-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>osgi-over-slf4j</artifactId>

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.slf4j</groupId>
88
<artifactId>slf4j-parent</artifactId>
9-
<version>1.7.21-SNAPSHOT</version>
9+
<version>1.7.22-SNAPSHOT</version>
1010

1111
<packaging>pom</packaging>
1212
<name>SLF4J</name>
@@ -74,6 +74,7 @@
7474
<module>integration</module>
7575
<module>slf4j-site</module>
7676
<module>slf4j-migrator</module>
77+
<module>slf4j-bom</module>
7778
</modules>
7879

7980
<dependencies>

slf4j-android/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.slf4j</groupId>
99
<artifactId>slf4j-parent</artifactId>
10-
<version>1.7.21-SNAPSHOT</version>
10+
<version>1.7.22-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>slf4j-android</artifactId>

slf4j-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.slf4j</groupId>
99
<artifactId>slf4j-parent</artifactId>
10-
<version>1.7.21-SNAPSHOT</version>
10+
<version>1.7.22-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>slf4j-api</artifactId>

slf4j-api/src/main/java/org/slf4j/LoggerFactory.java

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
* <p/>
5555
* <p/>
5656
* Please note that all methods in <code>LoggerFactory</code> are static.
57-
*
58-
*
57+
*
58+
*
5959
* @author Alexander Dorokhine
6060
* @author Robert Elliot
6161
* @author Ceki G&uuml;lc&uuml;
62-
*
62+
*
6363
*/
6464
public final class LoggerFactory {
6565

@@ -140,7 +140,8 @@ private static boolean messageContainsOrgSlf4jImplStaticLoggerBinder(String msg)
140140
private final static void bind() {
141141
try {
142142
Set<URL> staticLoggerBinderPathSet = null;
143-
// skip check under android, see also http://jira.qos.ch/browse/SLF4J-328
143+
// skip check under android, see also
144+
// http://jira.qos.ch/browse/SLF4J-328
144145
if (!isAndroid()) {
145146
staticLoggerBinderPathSet = findPossibleStaticLoggerBinderPathSet();
146147
reportMultipleBindingAmbiguity(staticLoggerBinderPathSet);
@@ -149,6 +150,7 @@ private final static void bind() {
149150
StaticLoggerBinder.getSingleton();
150151
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
151152
reportActualBinding(staticLoggerBinderPathSet);
153+
fixSubstituteLoggers();
152154
replayEvents();
153155
// release all resources in SUBST_FACTORY
154156
SUBST_FACTORY.clear();
@@ -178,25 +180,22 @@ private final static void bind() {
178180
}
179181
}
180182

183+
private static void fixSubstituteLoggers() {
184+
synchronized (SUBST_FACTORY) {
185+
SUBST_FACTORY.postInitialization();
186+
for (SubstituteLogger substLogger : SUBST_FACTORY.getLoggers()) {
187+
Logger logger = getLogger(substLogger.getName());
188+
substLogger.setDelegate(logger);
189+
}
190+
}
191+
192+
}
193+
181194
static void failedBinding(Throwable t) {
182195
INITIALIZATION_STATE = FAILED_INITIALIZATION;
183196
Util.report("Failed to instantiate SLF4J LoggerFactory", t);
184197
}
185198

186-
private final static void fixSubstitutedLoggers() {
187-
List<SubstituteLogger> loggers = SUBST_FACTORY.getLoggers();
188-
189-
if (loggers.isEmpty()) {
190-
return;
191-
}
192-
193-
for (SubstituteLogger subLogger : loggers) {
194-
Logger logger = getLogger(subLogger.getName());
195-
subLogger.setDelegate(logger);
196-
}
197-
198-
SUBST_FACTORY.clear();
199-
}
200199
private static void replayEvents() {
201200
final LinkedBlockingQueue<SubstituteLoggingEvent> queue = SUBST_FACTORY.getEventQueue();
202201
final int queueSize = queue.size();
@@ -285,13 +284,15 @@ private final static void versionSanityCheck() {
285284
}
286285
}
287286

288-
// We need to use the name of the StaticLoggerBinder class, but we can't reference
287+
// We need to use the name of the StaticLoggerBinder class, but we can't
288+
// reference
289289
// the class itself.
290290
private static String STATIC_LOGGER_BINDER_PATH = "org/slf4j/impl/StaticLoggerBinder.class";
291291

292292
static Set<URL> findPossibleStaticLoggerBinderPathSet() {
293293
// use Set instead of list in order to deal with bug #138
294-
// LinkedHashSet appropriate here because it preserves insertion order during iteration
294+
// LinkedHashSet appropriate here because it preserves insertion order
295+
// during iteration
295296
Set<URL> staticLoggerBinderPathSet = new LinkedHashSet<URL>();
296297
try {
297298
ClassLoader loggerFactoryClassLoader = LoggerFactory.class.getClassLoader();
@@ -316,9 +317,9 @@ private static boolean isAmbiguousStaticLoggerBinderPathSet(Set<URL> binderPathS
316317
}
317318

318319
/**
319-
* Prints a warning message on the console if multiple bindings were found on the class path.
320-
* No reporting is done otherwise.
321-
*
320+
* Prints a warning message on the console if multiple bindings were found
321+
* on the class path. No reporting is done otherwise.
322+
*
322323
*/
323324
private static void reportMultipleBindingAmbiguity(Set<URL> binderPathSet) {
324325
if (isAmbiguousStaticLoggerBinderPathSet(binderPathSet)) {
@@ -345,10 +346,11 @@ private static void reportActualBinding(Set<URL> binderPathSet) {
345346
}
346347

347348
/**
348-
* Return a logger named according to the name parameter using the statically
349-
* bound {@link ILoggerFactory} instance.
350-
*
351-
* @param name The name of the logger.
349+
* Return a logger named according to the name parameter using the
350+
* statically bound {@link ILoggerFactory} instance.
351+
*
352+
* @param name
353+
* The name of the logger.
352354
* @return logger
353355
*/
354356
public static Logger getLogger(String name) {
@@ -357,20 +359,25 @@ public static Logger getLogger(String name) {
357359
}
358360

359361
/**
360-
* Return a logger named corresponding to the class passed as parameter, using
361-
* the statically bound {@link ILoggerFactory} instance.
362-
*
363-
* <p>In case the the <code>clazz</code> parameter differs from the name of
364-
* the caller as computed internally by SLF4J, a logger name mismatch warning will be
365-
* printed but only if the <code>slf4j.detectLoggerNameMismatch</code> system property is
366-
* set to true. By default, this property is not set and no warnings will be printed
367-
* even in case of a logger name mismatch.
362+
* Return a logger named corresponding to the class passed as parameter,
363+
* using the statically bound {@link ILoggerFactory} instance.
364+
*
365+
* <p>
366+
* In case the the <code>clazz</code> parameter differs from the name of the
367+
* caller as computed internally by SLF4J, a logger name mismatch warning
368+
* will be printed but only if the
369+
* <code>slf4j.detectLoggerNameMismatch</code> system property is set to
370+
* true. By default, this property is not set and no warnings will be
371+
* printed even in case of a logger name mismatch.
368372
*
369-
* @param clazz the returned logger will be named after clazz
373+
* @param clazz
374+
* the returned logger will be named after clazz
370375
* @return logger
371-
*
372-
*
373-
* @see <a href="http://www.slf4j.org/codes.html#loggerNameMismatch">Detected logger name mismatch</a>
376+
*
377+
*
378+
* @see <a
379+
* href="http://www.slf4j.org/codes.html#loggerNameMismatch">Detected
380+
* logger name mismatch</a>
374381
*/
375382
public static Logger getLogger(Class<?> clazz) {
376383
Logger logger = getLogger(clazz.getName());
@@ -394,7 +401,7 @@ private static boolean nonMatchingClasses(Class<?> clazz, Class<?> autoComputedC
394401
* <p/>
395402
* <p/>
396403
* ILoggerFactory instance is bound with this class at compile time.
397-
*
404+
*
398405
* @return the ILoggerFactory instance in use
399406
*/
400407
public static ILoggerFactory getILoggerFactory() {

slf4j-api/src/main/java/org/slf4j/helpers/SubstituteLoggerFactory.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
package org.slf4j.helpers;
2626

2727
import java.util.ArrayList;
28+
import java.util.HashMap;
2829
import java.util.List;
29-
import java.util.concurrent.ConcurrentHashMap;
30-
import java.util.concurrent.ConcurrentMap;
30+
import java.util.Map;
3131
import java.util.concurrent.LinkedBlockingQueue;
3232

3333
import org.slf4j.ILoggerFactory;
@@ -44,17 +44,15 @@ public class SubstituteLoggerFactory implements ILoggerFactory {
4444

4545
boolean postInitialization = false;
4646

47-
final ConcurrentMap<String, SubstituteLogger> loggers = new ConcurrentHashMap<String, SubstituteLogger>();
47+
final Map<String, SubstituteLogger> loggers = new HashMap<String, SubstituteLogger>();
4848

4949
final LinkedBlockingQueue<SubstituteLoggingEvent> eventQueue = new LinkedBlockingQueue<SubstituteLoggingEvent>();
5050

51-
public Logger getLogger(String name) {
51+
synchronized public Logger getLogger(String name) {
5252
SubstituteLogger logger = loggers.get(name);
5353
if (logger == null) {
54-
logger = new SubstituteLogger(name, eventQueue);
55-
SubstituteLogger oldLogger = loggers.putIfAbsent(name, logger);
56-
if (oldLogger != null)
57-
logger = oldLogger;
54+
logger = new SubstituteLogger(name, eventQueue, postInitialization);
55+
loggers.put(name, logger);
5856
}
5957
return logger;
6058
}
@@ -71,6 +69,10 @@ public LinkedBlockingQueue<SubstituteLoggingEvent> getEventQueue() {
7169
return eventQueue;
7270
}
7371

72+
public void postInitialization() {
73+
postInitialization = true;
74+
}
75+
7476
public void clear() {
7577
loggers.clear();
7678
eventQueue.clear();

slf4j-api/src/test/java/org/slf4j/LoggerAccessingThread.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package org.slf4j;
2626

27+
import java.util.List;
2728
import java.util.concurrent.CyclicBarrier;
2829
import java.util.concurrent.atomic.AtomicLong;
2930

@@ -33,9 +34,11 @@ public class LoggerAccessingThread extends Thread {
3334
final CyclicBarrier barrier;
3435
final int count;
3536
final AtomicLong eventCount;
36-
37-
public LoggerAccessingThread(final CyclicBarrier barrier, final int count, final AtomicLong eventCount) {
37+
List<Logger> loggerList;
38+
39+
public LoggerAccessingThread(final CyclicBarrier barrier, List<Logger> loggerList, final int count, final AtomicLong eventCount) {
3840
this.barrier = barrier;
41+
this.loggerList = loggerList;
3942
this.count = count;
4043
this.eventCount = eventCount;
4144
}
@@ -50,6 +53,7 @@ public void run() {
5053
String loggerNamePrefix = this.getClass().getName();
5154
for (int i = 0; i < LOOP_LEN; i++) {
5255
Logger logger = LoggerFactory.getLogger(loggerNamePrefix + "-" + count + "-" + i);
56+
loggerList.add(logger);
5357
Thread.yield();
5458
logger.info("in run method");
5559
eventCount.getAndIncrement();

0 commit comments

Comments
 (0)