Scala配置logback

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Scala配置logback相关的知识,希望对你有一定的参考价值。

参考技术A scala+spark的工程中采用maven构建

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 ...... ")

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

<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>

以上是关于Scala配置logback的主要内容,如果未能解决你的问题,请参考以下文章

logback.xml文件配置标准输出和每日滚动文件追加器

scala01下载安装与配置

scala01下载安装与配置

假期学习配置Scala环境(Ubuntu)以及配套Scala编程实验

关于scala环境配置详解

scala环境变量配置