如何在zookeeper中使用Logback而不是log4j?

时间:2017-02-17 17:03:41

标签: java log4j logback slf4j apache-zookeeper

Zookeeper文档说可以使用LOGBack作为日志记录框架。我想知道步骤,如何在zookeeper中设置logback而不是loj4j?

2 个答案:

答案 0 :(得分:1)

对于Gradle配置的项目,我已经成功使用了它:

dependencies {
    compile(group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.4.10') {
        exclude group: 'log4j'
        exclude group: 'org.slf4j', module: 'slf4j-log4j12'
    }
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    runtime group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
}

答案 1 :(得分:1)

对于Maven项目:

在pom.xml中添加以下依赖项

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>2.0.0-alpha0</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.3.0-alpha5</version>
    </dependency>

logback.xml中为Zookeepr日志添加记录器和附加器

<appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>/var/log/zk-app.log</file>
    <encoder>
        <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
    <append>true</append>
</appender>
<logger name="org.apache.zookeeper" level="DEBUG" additivity="false">
    <appender-ref ref="FILE" />
</logger>