consoleCaptor.getStandardOutput() doesn't work
See original GitHub issueDescribe the bug
Hello, My issue is that with the same way as it is explained in the README I tried to use consoleCaptor.getStandardOutput() since I’m using @QuarkusTest but it gets nothing from the output, Even though the console is showing multiple json logs in the output.
@QuarkusTest
public class TestLog {
ObjectMapper mapper = new ObjectMapper();
@Test
public void testLogIsInJsonFormat() {
try (ConsoleCaptor consoleCaptor = new ConsoleCaptor()) {
QueryClass query = new QueryClass();
query.querySomeItem(null, null);
List<String> standardOutPut = consoleCaptor.getStandardOutput(); // this list returns empty
assertTrue(isValid(standardOutPut.get(1)));
}
}
}
{"timestamp":"2022-08-10T09:32:41.109+03:00","sequence":76,"loggerClassName":"org.jboss.logging.Logger","loggerName":"io.quarkus.amazon.lambda.runtime.AbstractLambdaPollLoop","level":"INFO","message":"Listening on: http://localhost:8081/_lambda_/2018-06-01/runtime/invocation/next","threadName":"Lambda Thread (TEST)","threadId":127,"mdc":{},"ndc":"","hostName":"my-laptop-name","processName":"JUnitStarter","processId":48118}
java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 0 // This means nothing was captured from the logs
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>logcaptor</artifactId>
<version>2.7.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>consolecaptor</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
I suspect that maybe because I’m using @JbossLog annotation, but then how this can be used with that JBossLog ?
Environmental Data:
- Java Version 17
- Maven Version 3.8.5
- OS (MacOS)
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
c# - How to spawn a process and capture its STDOUT in .NET?
I need to spawn a child process that is a console application, and capture its output. I wrote up the following code for...
Read more >process.stdout.write calls don't show in the console ... - GitHub
11.4 on my Windows machine I was not able to capture console.log() output in the Debug Console without adding "outputCapture": "std" in my ......
Read more >Console API — Rich 12.6.0 documentation
The console class has an input() method which works in the same way as Python's built-in input() function, but can use anything that...
Read more >Troubleshoot an unreachable instance - AWS Documentation
To get console output. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the left navigation pane, choose Instances, and select the ...
Read more >subprocess — Subprocess management — Python 3.11.1 ...
This module does not work or is not available on WebAssembly platforms ... If you wish to capture and combine both streams into...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It seems like the main issue is because of the
@QuarkusTestannotation. I discovered thatQuarkusTestis using a ConsoleHandler from the Jboss Logger library. The ConsoleHandler uses the System.out to log everything to the console. ConsoleCapture should manipulate the System.out, but fails to because the ConsoleHandler is initialized before ConsoleCaptor because of the QuarkusTest annotation. The good news is that I found a solution, however it will take some time to finilize it. I think by one week it should be ready, maybe earlier. So my advice is to drop LogCaptor as it is having issues because of multiple classloaders caused by Quarkus, which is unfortunally not fixable. And just wait for the new release of ConsoleCaptor.This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.