Skip to content

Commit e69d8fd

Browse files
committed
Feature to allow suppressing unsuccessful init error message
1 parent 1c6cbf0 commit e69d8fd

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

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

Lines changed: 17 additions & 13 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

@@ -75,6 +75,7 @@ public final class LoggerFactory {
7575

7676
static final String UNSUCCESSFUL_INIT_URL = CODES_PREFIX + "#unsuccessfulInit";
7777
static final String UNSUCCESSFUL_INIT_MSG = "org.slf4j.LoggerFactory could not be successfully initialized. See also " + UNSUCCESSFUL_INIT_URL;
78+
static final String UNSUCCESSFUL_INIT_MSG_SUPPRESSION_SYSTEM_PROPERTY = "slf4j.suppressInitError";
7879

7980
static final int UNINITIALIZED = 0;
8081
static final int ONGOING_INITIALIZATION = 1;
@@ -158,9 +159,12 @@ private final static void bind() {
158159
String msg = ncde.getMessage();
159160
if (messageContainsOrgSlf4jImplStaticLoggerBinder(msg)) {
160161
INITIALIZATION_STATE = NOP_FALLBACK_INITIALIZATION;
161-
Util.report("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
162-
Util.report("Defaulting to no-operation (NOP) logger implementation");
163-
Util.report("See " + NO_STATICLOGGERBINDER_URL + " for further details.");
162+
boolean suppressError = Util.safeGetBooleanSystemProperty(UNSUCCESSFUL_INIT_MSG_SUPPRESSION_SYSTEM_PROPERTY);
163+
if (!suppressError) {
164+
Util.report("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
165+
Util.report("Defaulting to no-operation (NOP) logger implementation");
166+
Util.report("See " + NO_STATICLOGGERBINDER_URL + " for further details.");
167+
}
164168
} else {
165169
failedBinding(ncde);
166170
throw ncde;
@@ -319,7 +323,7 @@ private static boolean isAmbiguousStaticLoggerBinderPathSet(Set<URL> binderPathS
319323
/**
320324
* Prints a warning message on the console if multiple bindings were found
321325
* on the class path. No reporting is done otherwise.
322-
*
326+
*
323327
*/
324328
private static void reportMultipleBindingAmbiguity(Set<URL> binderPathSet) {
325329
if (isAmbiguousStaticLoggerBinderPathSet(binderPathSet)) {
@@ -348,7 +352,7 @@ private static void reportActualBinding(Set<URL> binderPathSet) {
348352
/**
349353
* Return a logger named according to the name parameter using the
350354
* statically bound {@link ILoggerFactory} instance.
351-
*
355+
*
352356
* @param name
353357
* The name of the logger.
354358
* @return logger
@@ -361,20 +365,20 @@ public static Logger getLogger(String name) {
361365
/**
362366
* Return a logger named corresponding to the class passed as parameter,
363367
* using the statically bound {@link ILoggerFactory} instance.
364-
*
368+
*
365369
* <p>
366370
* In case the the <code>clazz</code> parameter differs from the name of the
367371
* caller as computed internally by SLF4J, a logger name mismatch warning
368372
* will be printed but only if the
369373
* <code>slf4j.detectLoggerNameMismatch</code> system property is set to
370374
* true. By default, this property is not set and no warnings will be
371375
* printed even in case of a logger name mismatch.
372-
*
376+
*
373377
* @param clazz
374378
* the returned logger will be named after clazz
375379
* @return logger
376-
*
377-
*
380+
*
381+
*
378382
* @see <a
379383
* href="http://www.slf4j.org/codes.html#loggerNameMismatch">Detected
380384
* logger name mismatch</a>
@@ -401,7 +405,7 @@ private static boolean nonMatchingClasses(Class<?> clazz, Class<?> autoComputedC
401405
* <p/>
402406
* <p/>
403407
* ILoggerFactory instance is bound with this class at compile time.
404-
*
408+
*
405409
* @return the ILoggerFactory instance in use
406410
*/
407411
public static ILoggerFactory getILoggerFactory() {

0 commit comments

Comments
 (0)