Logging

Spring MVC 中的 DEBUG 级别的日志记录设计得紧凑、最少且便于阅读。它着重于有价值的信息片段,这些片段一用再用,而不是其他信息片段,后者只在调试特定问题时才有用。

DEBUG-level logging in Spring MVC is designed to be compact, minimal, and human-friendly. It focuses on high-value bits of information that are useful over and over again versus others that are useful only when debugging a specific issue.

TRACE 级别的日志记录通常遵循与 DEBUG 相同的原则(例如,也不应该泛滥成灾),但可用于调试任何问题。此外,一些日志消息可能会在 TRACE 与 DEBUG 中显示不同的详细程度。

TRACE-level logging generally follows the same principles as DEBUG (and, for example, also should not be a fire hose) but can be used for debugging any issue. In addition, some log messages may show a different level of detail at TRACE versus DEBUG.

良好的日志记录得益于使用日志的经验。如果你发现任何不符合既定目标的信息,请告知我们。

Good logging comes from the experience of using the logs. If you spot anything that does not meet the stated goals, please let us know.

Sensitive Data

DEBUG 和 TRACE 记录可能会记录敏感信息。这就是为什么默认情况下请求参数和标头会被掩码,并且必须通过 DispatcherServlet 上的 enableLoggingRequestDetails 属性显式启用它们的完整记录。

DEBUG and TRACE logging may log sensitive information. This is why request parameters and headers are masked by default and their logging in full must be enabled explicitly through the enableLoggingRequestDetails property on DispatcherServlet.

以下示例展示了如何通过使用 Java 配置执行此操作:

The following example shows how to do so by using Java configuration:

  • Java

  • Kotlin

public class MyInitializer
		extends AbstractAnnotationConfigDispatcherServletInitializer {

	@Override
	protected Class<?>[] getRootConfigClasses() {
		return ... ;
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return ... ;
	}

	@Override
	protected String[] getServletMappings() {
		return ... ;
	}

	@Override
	protected void customizeRegistration(ServletRegistration.Dynamic registration) {
		registration.setInitParameter("enableLoggingRequestDetails", "true");
	}

}
class MyInitializer : AbstractAnnotationConfigDispatcherServletInitializer() {

	override fun getRootConfigClasses(): Array<Class<*>>? {
		return ...
	}

	override fun getServletConfigClasses(): Array<Class<*>>? {
		return ...
	}

	override fun getServletMappings(): Array<String> {
		return ...
	}

	override fun customizeRegistration(registration: ServletRegistration.Dynamic) {
		registration.setInitParameter("enableLoggingRequestDetails", "true")
	}
}