简体   繁体   English

在 Lombok 中使用 Logback

[英]Using Logback with Lombok

I have a class that looks like so:我有一个看起来像这样的课程:

@Slf4j
public class MyTestApplication {
    public static void main(String[] argv) { 
        log.info("IN HERE!");
    }
}

In my build.gradle I have the following dependencies:在我的build.gradle我有以下依赖项:

dependencies {
  compile group: 'org.projectlombok', name: 'lombok', version: '1.16.20'
  compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
  compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
  compile group: 'private.company.dep', name: 'redacted', version: '1.0.0'
}

And I have a default logback.xml我有一个默认的logback.xml

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>
            %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
        </Pattern>
    </layout>
</appender>

<logger name="com.mkyong.web" level="debug"
        additivity="false">
    <appender-ref ref="STDOUT" />
</logger>

<root level="error">
    <appender-ref ref="STDOUT" />
</root>

The problem I am having is when I build my application I get the following error:我遇到的问题是,当我构建应用程序时,出现以下错误:

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

The private company dependency possibly has a dependency on Log4j2.私人公司依赖可能依赖于 Log4j2。 I'm guessing this is the source my error.我猜这是我错误的来源。 How can I disable/override it's Log4j2 dependency so I can use Logback in this application?如何禁用/覆盖它的 Log4j2 依赖项,以便我可以在此应用程序中使用 Logback?

You can add log4j-over-slf4j to your classpath to define a bridge between log4j and slf4j:您可以将 log4j-over-slf4j 添加到类路径中以定义 log4j 和 slf4j 之间的桥梁:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>1.7.29</version>
</dependency>

The documentation is here: https://www.slf4j.org/legacy.html#log4j-over-slf4j文档在这里: https : //www.slf4j.org/legacy.html#log4j-over-slf4j

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM