spring中默认的日志框架是哪一个呢?
Spring日志框架简介
spring中默认日志框架并不固定 我们可以采用项目的配置和依赖项调整Spring中使用的日志框架
Spring Boot默认日志框架
- 默认使用Logback: Spring Boot默认集成Logback作为日志实现 - 如果你创建一个新Spring Boot项目 且 没有引入其他日志框架 Spring Boot会自动配置Logback并使用它进行日志记录
日志抽象层
- SLF4J(Simple Logging Facade for Java): Spring 和 Spring Boot 使用 SLF4J 作为日志抽象层。 - SLF4J是一个简单的日志门面 允许你在应用程序中编写日志代码时不必绑定到特定日志实现 - 实际的日志记录由底层的日志实现(如 Logback、Log4j2 或 JDK自带`java.util.logging`)完成 其他日志框架的支持 -Log4j2: 如果你在项目中引入了 Log4j2 的依赖, Spring Boot 会自动切换到 Log4j2 作为日志实现。 -Java Util Logging(JUL): 如果项目中没有其他日志框架, Spring Boot 也会支持 JDK 自带的 `java.util.logging`。 -Commons Logging: 虽然Commons Logging在早期版本中较为常见, 大多数Spring Boot项目 通常不推荐使用它 建议使用SLF4J和Logback或Log4j2例
使用Logback(默认) <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency> 使用 Log4j2 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>
总结
- Spring Boot 默认使用Logback作为日志实现 并通过SLF4J提供日志抽象层。 - 如果你需要使用其他日志框架 只需引入相应的依赖 Spring Boot会自动进行配置切换
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。