Scala配置logback

scala+spark的工程中采用maven构建

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

2、maven下加入

     com.typesafe.scala-logging

      scala-logging_2.11

      3.5.0

     ch.qos.logback

      logback-classic

       1.2.3

3、使用的方法

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

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

警告,控制台却出现如下提示:


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.


其实很简单,查看问题说明引入了多个slf4j,在maven下面饮用的jar包也可以看到,找到依赖该jar的包,修改如下,增加exclusions

       org.apache.spark

        spark-core_2.11

            ${spark}

       

           

                  org.slf4j 

                   slf4j-log4j12

           

           

                 log4j

                 log4j

           

         

你可能感兴趣的:(Scala配置logback)