dubbo项目中使用logback输出日志

初次建立dubbo项目,并启动服务提供方时会看到如下的警告。

log4j:WARN No appenders could be found for logger (com.alibaba.dubbo.common.logger.LoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

现在希望使用logback来输出日志,因此需要添加相关依赖。
根据 http://www.slf4j.org/legacy.html slf4j官网配置指南可以看到,共需要添加如下的三个依赖。其作用可以在给出的链接中看到。

        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-apiartifactId>
            <version>1.7.7version>
        dependency>
        <dependency>
            <groupId>ch.qos.logbackgroupId>
            <artifactId>logback-classicartifactId>
            <version>1.1.3version>
        dependency>
        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>log4j-over-slf4jartifactId>
            <version>1.7.7version>
        dependency>

根据官网提示

log4j-over-slf4j
SLF4J ship with a module called log4j-over-slf4j. It allows log4j users to migrate existing applications to SLF4J without changing a single line of code but simply by replacing the log4j.jar file with log4j-over-slf4j.jar, as described below.

因此在dubbo的依赖中要排除对log4j的依赖。

        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>dubboartifactId>
            <version>2.8.4version>
            <exclusions>
                <exclusion>
                    <groupId>log4jgroupId>
                    <artifactId>log4jartifactId>
                exclusion>
            exclusions>
        dependency>

随后添加logback配置文件logback.xml在项目的资源目录中,并启动服务提供者可以看到日志输出。

你可能感兴趣的:(dubbo)