Scala配置logback

scala+spark的工程中采用maven構(gòu)建

1、首先在src/main/resources下加入logback.xml

2、maven下加入

<dependency>

? ? ?<groupId>com.typesafe.scala-logging</groupId>

? ? ? <artifactId>scala-logging_2.11</artifactId>

? ? ? <version>3.5.0</version>

</dependency>

<dependency>

? ? ?<groupId>ch.qos.logback</groupId>

? ? ? <artifactId>logback-classic</artifactId>

? ? ? ?<version>1.2.3</version>

</dependency>

3、使用的方法

private[this]val logger =Logger(this.getClass)

logger.info("server ready ...... ")

警告,控制臺卻出現(xiàn)如下提示:


SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/Users/nibaohua/onway/mavenpro/repo/org/slf4j/slf4j-log4j12/1.7.16/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/Users/nibaohua/onway/mavenpro/repo/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

log4j:WARN No appenders could be found for logger (Test1$).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


其實(shí)很簡單,查看問題說明引入了多個(gè)slf4j,在maven下面飲用的jar包也可以看到,找到依賴該jar的包,修改如下,增加exclusions

<dependency>

? ? ? ?<groupId>org.apache.spark</groupId>

? ? ? ? <artifactId>spark-core_2.11</artifactId>

? ? ? ? ? ? <version>${spark}</version>

? ? ? ? <exclusions>

? ? ? ? ? ? <exclusion>

? ? ? ? ? ? ? ? ? <groupId>org.slf4j</groupId>?

? ? ? ? ? ? ? ? ? ?<artifactId>slf4j-log4j12</artifactId>

? ? ? ? ? ? </exclusion>

? ? ? ? ? ?<exclusion>

? ? ? ? ? ? ? ? ?<groupId>log4j</groupId>

? ? ? ? ? ? ? ? ?<artifactId>log4j</artifactId>

? ? ? ? ? ?</exclusion>

? ? ? ? ?</exclusions>

</dependency>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容