Java 使用 Lombok 进行 Spring Boot 日志记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43901810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Boot logging with Lombok
提问by dkanejs
I would like to use Project Lombok's log annotationin 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 Boot 项目中使用Project Lombok 的日志注释,但我不想失去能够从application.properties
.
The Spring logging docs aren't overly clear on what the default logging implementation should be used, and there are 7 Lombok choices!
Spring 日志记录文档并不太清楚应该使用什么默认日志记录实现,并且有 7 种 Lombok 选择!
Any ideas?
有任何想法吗?
采纳答案by P?r Nilsson
I would use @Slf4j. Tested the following and it works as expected.
我会使用@Slf4j。测试了以下内容,它按预期工作。
@SpringBootApplication
@Slf4j
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
log.info("testing logging with lombok");
}
}
Then you can change the logging level as described here.
然后,您可以按照此处所述更改日志记录级别。
logging.level.com.example.DemoApplication=WARN
Note: Below clarifies that SLF4J is correctly handled but point is made in last 5 words!
注意:下面澄清了 SLF4J 的正确处理,但最后 5 个字是重点!
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 SLF4Jwill all work correctly."
来自文档:“为 Java Util Logging、Log4J2 和 Logback 提供了默认配置。” ...“默认情况下,如果您使用 'Starters',Logback 将用于日志记录。还包括适当的 Logback 路由,以确保使用 Java Util Logging、Commons Logging、Log4J 或SLF4J 的依赖库都能正常工作。”