Lombok的Spring Boot日志记录 [英] Spring Boot logging with Lombok

查看:616
本文介绍了Lombok的Spring Boot日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Spring Boot项目中使用 Project Lombok的日志注释,但我不愿意不想失去能够从application.properties更改日志记录的功能.

I would like to use Project Lombok's log annotation in my Spring Boot projects but I don't want to lose the functionality of being able to change the logging from the application.properties.

Spring日志记录文档对于应该使用默认的日志记录实现方式并不太清楚,并且有7种Lombok选择!

The Spring logging docs aren't overly clear on what the default logging implementation should be used, and there are 7 Lombok choices!

有什么想法吗?

推荐答案

我会使用@ Slf4j.测试了以下内容,并且可以正常工作.

I would use @Slf4j. Tested the following and it works as expected.

@SpringBootApplication
@Slf4j
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
        log.info("testing logging with lombok");
    }
}

然后,您可以按照此处.

logging.level.com.example.DemoApplication=WARN

注意:以下内容说明SLF4J可以正确处理,但最后5个单词是正确的!

从文档中: 为Java Util Logging,Log4J2和Logback提供了默认配置." ... 默认情况下,如果使用'Starters',将使用Logback进行日志记录.还包括适当的Logback路由,以确保使用Java Util Logging,Commons Logging,Log4J或 SLF4J 的从属库所有正常工作."

From the docs: "Default configurations are provided for Java Util Logging, Log4J2 and Logback." ... "By default, If you use the ‘Starters’, Logback will be used for logging. Appropriate Logback routing is also included to ensure that dependent libraries that use Java Util Logging, Commons Logging, Log4J or SLF4J will all work correctly."

这篇关于Lombok的Spring Boot日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆