2012-10-29 42 views
3

我創建了一個包含所有依賴關係的jar文件,並使用slf4j + logback實現了日誌記錄。因此,我爲所有記錄器定義了一個logback.xml文件。然而,當我運行jar它給了我這個消息:未能加載類'org.slf4j.impl.StaticLoggerBinder'

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 

我沒有看到任何記錄發生。在我解壓縮jar文件後,我可以看到org.slf4j文件夾。我不知道爲什麼這不起作用。

回答

3

http://www.slf4j.org/codes.html#StaticLoggerBinder(在該消息中的鏈接):

當org.slf4j.impl.StaticLoggerBinder 類不能被加載到存儲器,將報告該誤差。當在類路徑上找不到合適的SLF4J綁定時,會發生這種情況。將 中的一個(並且只有一個)slf4j-nop.jar,slf4j-simple.jar, slf4j-log4j12.jar,slf4j-jdk14.jar或者類 上的logback-classic.jar路徑應該解決問題。 SINCE 1.6.0從SLF4J版本1.6起,在 沒有綁定,SLF4J將默認爲無操作(NOP) 記錄器實現。您可以從 項目下載頁面下載SLF4J綁定。

換句話說,你需要在你的類路徑中有一個slf4j後端,的logback。

0

這是一個scala項目嗎?如果是,那麼添加下面的依賴關係將有所幫助。它爲我工作。

"org.slf4j" % "slf4j-simple" % "1.7.12" 
+0

不解決它爲我的Scala項目。版本是否重要? – matanster

相關問題