如何在 Spring-boot 上显示完整的日志消息

How to show complete log messages on Spring-boot

我在历史记录中看到的大多数消息都是关于禁用日志的某些方面。我想要相反的。我看到很多消息,例如:

" DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor.traceDebug (91) - Writing [" <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2. (truncated)...]"

我想查看完整的、未截断的(在本例中)RSS 提要。知道如何说服 Spring/Logback/console/maven 这样做吗?

奖金问题 -- 我将如何编写测试来验证日志实际上没有被截断?我没有让他们以任何方式坚持,只是在控制台上。非常感谢!

使用 DEBUG 日志级别,Spring 仅记录截断的数据。使用 TRACE 日志级别,Spring 记录完整数据。

你可以配置类似

logging.level.org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor = TRACE

要测试写入日志的输出(如 System.out),请查看 OutputCapture

@ExtendWith(OutputCaptureExtension.class)
class OutputCaptureTests {

    @Test
    void testName(CapturedOutput output) {
        System.out.println("Hello World!");
        assertThat(output).contains("World");
    }

}

您还可以像这样在 HttpLogging 实体上设置 TRACE 日志记录级别:

logging.level.org.springframework.web.HttpLogging = TRACE