question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is OutputCaptureExtension supposed to support java.util.logging too?

See original GitHub issue

Hi, I ran into this problem below:

For each test, it passes. But if I run the test class, it always failed on the 2nd. Any ideas?

Thanks

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.logging.AbstractLoggingSystemTests;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;

import java.util.logging.Logger;

import static org.assertj.core.api.Assertions.assertThat;

@ExtendWith(OutputCaptureExtension.class)
public class TestCapture extends AbstractLoggingSystemTests {
    static Logger LOG=Logger.getLogger(TestCapture.class.getName());


    @Test
    void test(CapturedOutput output) {
        System.out.println("ok");
        LOG.warning("error");
        assertThat(output).contains("ok");
        assertThat(output).contains("error");

    }

    @Test
    void test2(CapturedOutput output) {
        LOG.info("not ok");
        LOG.warning("type 1 error");
        assertThat(output).contains("not");
        assertThat(output).contains("type 1");
    }

}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wilkinsonacommented, Oct 3, 2022

I don’t think we should do this automatically, but I think it would be worth mentioning it in the javadoc. We could also mention the need for follow=true when configuring a Log4j2 console appender.

0reactions
jianlinshicommented, Oct 1, 2022

Awesome! Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Package java.util.logging - Oracle Help Center
The central goal of the logging APIs is to support maintaining and servicing software at customer sites. There are four main target uses...
Read more >
Do you find java.util.logging sufficient? [closed] - Stack Overflow
In summary, Java JDK logging is fine, but a standardized API that is used in my third party libraries will save you time...
Read more >
How To Unit Log Statements With JUnit 5 - Callibrity
This post is to demonstrate how to use JUnit 5 Extensions to help unit test log statements, along with providing sample code via...
Read more >
Java Logging Guide: The Basics | CrowdStrike
In this overview, we introduce the basic logging concepts for Java applications as well as available logging frameworks and their supported ...
Read more >
Replacing logging APIs with the Java System Logger
Log4j2. Log4j2 has a module, log4j-jpl , that is supposed to add support for the JDK System.Logger . By placing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found