此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 Spring Framework 6.2.10spring-doc.cadn.net.cn

Logging

Spring 带有自己的 Commons Logging 桥 在spring-jcl模块。该实现检查是否存在 Log4j 2.x API 和 SLF4J 1.7 API 的 API 和 SLF4J 1.7 API,并使用其中第一个作为 日志记录实现,回退到 Java 平台的核心日志记录工具( 称为 JULjava.util.logging),如果 Log4j 2.x 和 SLF4J 都不可用。spring-doc.cadn.net.cn

将 Log4j 2.x 或 Logback(或其他 SLF4J 提供程序)放入您的类路径中,无需任何额外的 桥梁,并让框架自动适应您的选择。有关更多信息,请参阅 Spring 启动日志记录参考文档spring-doc.cadn.net.cn

Spring 的 Commons Logging 变体仅用于基础设施日志记录 核心框架和扩展中的用途。spring-doc.cadn.net.cn

对于应用程序代码中的日志记录需求,最好直接使用 Log4j 2.x、SLF4J 或 JUL。spring-doc.cadn.net.cn

一个Log可以通过以下方式检索实现org.apache.commons.logging.LogFactory如 以下示例。spring-doc.cadn.net.cn

public class MyBean {
	private final Log log = LogFactory.getLog(getClass());
	// ...
}
class MyBean {
	private val log = LogFactory.getLog(javaClass)
	// ...
}