Slf4j-error-messages
SLF4J-エラーメッセージ
この章では、SLF4Jの操作中に表示されるさまざまなエラーメッセージまたは警告と、それらのメッセージの原因/意味について説明します。
クラス「org.slf4j.impl.StaticLoggerBinder」のロードに失敗しました。
これは、クラスパスでSLF4Jバインディングが提供されていない場合に発生する警告です。
以下は完全な警告です-
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codesl#StaticLoggerBinder for further
details.
これを解決するには、ロギングフレームワークバインディングのいずれかを追加する必要があります。 これについては、このチュートリアルの Hello world の章で説明されています。
注-これは、1.6.0〜1.8.0-beta2のSLF4Jのバージョンで発生します。
SLF4Jプロバイダーが見つかりませんでした
slf4j-1.8.0-beta2では、*「SLF4Jプロバイダーが見つかりませんでした」*という上記の警告はより明確です。
以下は完全な警告です-
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codesl#noProviders for further details.
クラスパスには、slf4j-apiバージョン1.8より前をターゲットとするSLF4Jバインディングが含まれています
SLF4J 1.8バージョンを使用しており、クラスパスに以前のバージョンのバインディングがあるが1.8のバインディングがない場合は、次のような警告が表示されます。
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codesl#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to
1.8.
SLF4J: Ignoring binding found at
[jar:file:/C:/Users/finddevguides/Desktop/Latest%20Tutorials/SLF4J%20Tutorial/
slf4j-1.7.25/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codesl#ignoredBindings for an explanation.
NoClassDefFoundError:org/apache/commons/logging/LogFactory
*slf4j-jcl* を使用していて、クラスパスに *slf4j-jcl.jar* しかない場合、以下のような例外が発生します。
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/logging/LogFactory
at org.slf4j.impl.JCLLoggerFactory.getLogger(JCLLoggerFactory.java:77)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
at SLF4JExample.main(SLF4JExample.java:8)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.logging.LogFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
これを解決するには、 commons-logging.jar をクラスパスに追加する必要があります。
クラスパスでjcl-over-slf4j.jarとバインドされたslf4j-jcl.jarの両方を検出しました。
バインディング slf4j-jcl.jar はslf4jロガーの呼び出しをJCLにリダイレクトし、 jcl-over-slf4j.jar はJCLロガーの呼び出しをslf4jにリダイレクトします。 したがって、プロジェクトのクラスパスに両方を含めることはできません。 これを行うと、次のような例外が発生します。
SLF4J: Detected both jcl-over-slf4j.jar AND bound slf4j-jcl.jar on the class
path, preempting StackOverflowError.
SLF4J: See also http://www.slf4j.org/codesl#jclDelegationLoop for more
details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:71)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:42)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at SLF4JExample.main(SLF4JExample.java:8)
Caused by: java.lang.IllegalStateException: Detected both jcl-over-slf4j.jar
AND bound slf4j-jcl.jar on the class path, preempting StackOverflowError. See
also http://www.slf4j.org/codesl#jclDelegationLoop for more details.
at org.slf4j.impl.JCLLoggerFactory.<clinit>(JCLLoggerFactory.java:54)
... 7 more
これを解決するには、いずれかのjarファイルを削除します。
ロガー名の不一致が検出されました
次の方法でLoggerオブジェクトを作成できます-
- * getLogger()*メソッドの引数として作成されるロガーの名前を渡します。
- このメソッドに引数としてクラスを渡す。
クラスを引数として渡すことによってロガーファクトリオブジェクトを作成しようとしている場合、およびシステムプロパティ slf4j.detectLoggerNameMismatch をtrueに設定している場合は、引数として* getLogger( )*メソッドと使用するクラスは同じでなければなりません。そうしないと、次の警告が表示されます-
「ロガー名の不一致が検出されました。
次の例を考えてください。
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SLF4JExample {
public static void main(String[] args) {
System.setProperty("slf4j.detectLoggerNameMismatch", "true");
//Creating the Logger object
Logger logger = LoggerFactory.getLogger(Sample.class);
//Logging the information
logger.info("Hi Welcome to Tutorilspoint");
}
}
ここでは、_slf4j.detectLoggerNameMismatch_プロパティをtrueに設定しました。 使用したクラスの名前は SLF4JExample で、getLogger()メソッドに渡したクラス名は Sample です。これらは両方とも等しくないため、次の警告が表示されます。
SLF4J: Detected logger name mismatch. Given name: "Sample"; computed name:
"SLF4JExample".
SLF4J: See http://www.slf4j.org/codesl#loggerNameMismatch for an
explanation
Dec 10, 2018 12:43:00 PM SLF4JExample main
INFO: Hi Welcome to Tutorilspoint
注-これはslf4j 1.7.9の後に発生します
クラスパスには複数のSLF4Jバインディングが含まれます。
クラスパスにはバインディングが1つしかありません。 複数のバインディングがある場合、バインディングとそれらの場所をリストする警告が表示されます。
たとえば、クラスパスに slf4j-jdk14.jar と slf4j-nop.jar のバインディングがある場合、次の警告が表示されます。
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/C:/Users/finddevguides/Desktop/Latest%20Tutorials/SLF4J%20Tutorial/
slf4j-1.7.25/slf4j-nop-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/Users/finddevguides/Desktop/Latest%20Tutorials/SLF4J%20Tutorial/
slf4j-1.7.25/slf4j-jdk14-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codesl#multiple_bindings for an
explanation.
SLF4J: Actual binding is of type [org.slf4j.helpers.NOPLoggerFactory]
クラスパスでlog4j-over-slf4j.jarとバインドされたslf4j-log4j12.jarの両方を検出しました
log4jロガーコールをslf4jにリダイレクトするには、 log4j-over-slf4j.jar バインディングを使用する必要があります。slf4jコールをlog4jにリダイレクトするには、 slf4j-log4j12.jar バインディングを使用する必要があります。
したがって、クラスパスに両方を含めることはできません。 その場合、次の例外が発生します。
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the
class path, preempting StackOverflowError.
SLF4J: See also http://www.slf4j.org/codesl#log4jDelegationLoop for more
details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at SLF4JExample.main(SLF4JExample.java:8)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar
AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
See also http://www.slf4j.org/codesl#log4jDelegationLoop for more details.