SpringBootTest 和 MockMvc 创建了大量控制台日志记录 - 如何禁用?
SpringBootTest and MockMvc creating an enormous amount of console logging - how to disable?
我们正在使用 @SpringBootTest
和 @Autowired private MockMvc mockMvc
属性来模拟对我们控制器的 HTTP 请求 类。
出于某种我们似乎无法确定的原因,这为每个测试用例创建了大量的日志记录,并用 千 行文本填充我们的日志看起来像:
build 18-May-2019 03:09:40 Async:
build 18-May-2019 03:09:40 Async started = false
build 18-May-2019 03:09:40 Async result = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Resolved Exception:
build 18-May-2019 03:09:40 Type = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 ModelAndView:
build 18-May-2019 03:09:40 View name = null
build 18-May-2019 03:09:40 View = null
build 18-May-2019 03:09:40 Model = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 FlashMap:
build 18-May-2019 03:09:40 Attributes = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletResponse:
build 18-May-2019 03:09:40 Status = 200
build 18-May-2019 03:09:40 Error message = null
build 18-May-2019 03:09:40 Headers = {X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY]}
build 18-May-2019 03:09:40 Content type = null
build 18-May-2019 03:09:40 Body =
build 18-May-2019 03:09:40 Forwarded URL = null
build 18-May-2019 03:09:40 Redirected URL = null
build 18-May-2019 03:09:40 Cookies = []
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletRequest:
build 18-May-2019 03:09:40 HTTP Method = POST
build 18-May-2019 03:09:40 Request URI = /api/v1/certification/applications
build 18-May-2019 03:09:40 Parameters = {}
build 18-May-2019 03:09:40 Headers = {Content-Type=[application/json;charset=UTF-8]}
build 18-May-2019 03:09:40 Body = {"applicationVersion":"1.0"}
build 18-May-2019 03:09:40 Session Attrs = {}
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Handler:
build 18-May-2019 03:09:40 Type = <redacted>
build 18-May-2019 03:09:40 Method = <redacted>
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Async:
build 18-May-2019 03:09:40 Async started = false
build 18-May-2019 03:09:40 Async result = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Resolved Exception:
build 18-May-2019 03:09:40 Type = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 ModelAndView:
build 18-May-2019 03:09:40 View name = null
build 18-May-2019 03:09:40 View = null
build 18-May-2019 03:09:40 Model = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 FlashMap:
build 18-May-2019 03:09:40 Attributes = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletResponse:
build 18-May-2019 03:09:40 Status = 200
build 18-May-2019 03:09:40 Error message = null
build 18-May-2019 03:09:40 Headers = {X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY]}
build 18-May-2019 03:09:40 Content type = null
build 18-May-2019 03:09:40 Body =
build 18-May-2019 03:09:40 Forwarded URL = null
build 18-May-2019 03:09:40 Redirected URL = null
build 18-May-2019 03:09:40 Cookies = []
我所有的互联网搜索和 Spring 引导测试文档阅读都没有结果。 此日志记录 来自哪里,我们如何关闭它?
我们已经详尽地扫描了我们的代码,并且确信我们不会 printing/responsible 它。
您必须从 application.properties 中的 spring 框架包中禁用信息记录器。在 application.properties.
中添加以下 属性
logging.level.org.springframework=OFF
这来自 MockMvc
。
您似乎已经覆盖了默认值并指示 Spring Boot 始终打印 MockMvc
的调试输出。
您应该能够通过声明 @AutoConfigureMockMvc(printOnlyOnFailure = true)
或省略 printOnlyOnFailure
标志来停用此功能,因为 true
是默认值。
您可以通过 print
属性配置输出模式——例如,@AutoConfigureMockMvc(print = MockMvcPrint.NONE)
.
我们正在使用 @SpringBootTest
和 @Autowired private MockMvc mockMvc
属性来模拟对我们控制器的 HTTP 请求 类。
出于某种我们似乎无法确定的原因,这为每个测试用例创建了大量的日志记录,并用 千 行文本填充我们的日志看起来像:
build 18-May-2019 03:09:40 Async:
build 18-May-2019 03:09:40 Async started = false
build 18-May-2019 03:09:40 Async result = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Resolved Exception:
build 18-May-2019 03:09:40 Type = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 ModelAndView:
build 18-May-2019 03:09:40 View name = null
build 18-May-2019 03:09:40 View = null
build 18-May-2019 03:09:40 Model = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 FlashMap:
build 18-May-2019 03:09:40 Attributes = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletResponse:
build 18-May-2019 03:09:40 Status = 200
build 18-May-2019 03:09:40 Error message = null
build 18-May-2019 03:09:40 Headers = {X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY]}
build 18-May-2019 03:09:40 Content type = null
build 18-May-2019 03:09:40 Body =
build 18-May-2019 03:09:40 Forwarded URL = null
build 18-May-2019 03:09:40 Redirected URL = null
build 18-May-2019 03:09:40 Cookies = []
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletRequest:
build 18-May-2019 03:09:40 HTTP Method = POST
build 18-May-2019 03:09:40 Request URI = /api/v1/certification/applications
build 18-May-2019 03:09:40 Parameters = {}
build 18-May-2019 03:09:40 Headers = {Content-Type=[application/json;charset=UTF-8]}
build 18-May-2019 03:09:40 Body = {"applicationVersion":"1.0"}
build 18-May-2019 03:09:40 Session Attrs = {}
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Handler:
build 18-May-2019 03:09:40 Type = <redacted>
build 18-May-2019 03:09:40 Method = <redacted>
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Async:
build 18-May-2019 03:09:40 Async started = false
build 18-May-2019 03:09:40 Async result = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Resolved Exception:
build 18-May-2019 03:09:40 Type = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 ModelAndView:
build 18-May-2019 03:09:40 View name = null
build 18-May-2019 03:09:40 View = null
build 18-May-2019 03:09:40 Model = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 FlashMap:
build 18-May-2019 03:09:40 Attributes = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletResponse:
build 18-May-2019 03:09:40 Status = 200
build 18-May-2019 03:09:40 Error message = null
build 18-May-2019 03:09:40 Headers = {X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY]}
build 18-May-2019 03:09:40 Content type = null
build 18-May-2019 03:09:40 Body =
build 18-May-2019 03:09:40 Forwarded URL = null
build 18-May-2019 03:09:40 Redirected URL = null
build 18-May-2019 03:09:40 Cookies = []
我所有的互联网搜索和 Spring 引导测试文档阅读都没有结果。 此日志记录 来自哪里,我们如何关闭它?
我们已经详尽地扫描了我们的代码,并且确信我们不会 printing/responsible 它。
您必须从 application.properties 中的 spring 框架包中禁用信息记录器。在 application.properties.
中添加以下 属性logging.level.org.springframework=OFF
这来自 MockMvc
。
您似乎已经覆盖了默认值并指示 Spring Boot 始终打印 MockMvc
的调试输出。
您应该能够通过声明 @AutoConfigureMockMvc(printOnlyOnFailure = true)
或省略 printOnlyOnFailure
标志来停用此功能,因为 true
是默认值。
您可以通过 print
属性配置输出模式——例如,@AutoConfigureMockMvc(print = MockMvcPrint.NONE)
.