Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Verbose logging introduced by LogCaptor #1849

Closed
wants to merge 3 commits into from

Conversation

joc-a
Copy link
Collaborator

@joc-a joc-a commented Aug 30, 2023

Adding the LogCaptor dependency caused the logging level to be DEBUG instead of INFO, even though it is configured to be INFO in log4j2.xml. This is a known issue (Hakky54/log-captor#8) because LogCaptor uses a different appender than the one configured in log4j2.xml. More details in this comment: Hakky54/log-captor#8 (comment).

The solution is to remove the dependency and create a custom appender which is used to test the logs.

Partially inspired by this.

Adding the LogCaptor dependency caused the logging level to be DEBUG instead of INFO, even though it is configured to be INFO in log4j2.xml. This is a known issue (Hakky54/log-captor#8) because LogCaptor uses a different appender than the one configured in log4j2.xml. More details in this comment: Hakky54/log-captor#8 (comment).

The solution is to remove the dependency and create a custom appender which is used to test the logs.
Add TestAppender programmatically for one test rather than enable it for all tests.
@Hakky54
Copy link
Contributor

Hakky54 commented Aug 31, 2023

@joc-a there is a solution for the issue you are facing. You can have logcaptor and mute all of the logs in the console or build output and still do the assertions. I use the following test resource which you can copy over https://github.com/Hakky54/sslcontext-kickstart/blob/master/sslcontext-kickstart/src/test/resources/logback-test.xml

I was waiting for your input on the issue you created here Hakky54/log-captor#47
However it seems like you already was working on a workaround with a native implementation with log4j2

Do you think it is worth to give it a shot with the logback-test.xml file?

@joc-a
Copy link
Collaborator Author

joc-a commented Aug 31, 2023

Hey @Hakky54. Thank you for your suggestion. I did try that solution at first after searching through the issues on GitHub, but it won't work for this case because it would completely mute all logs, including those that we would expect to see if there is something being logged that should not be there. I wanted the logging behaviour to be exactly the same as before introducing LogCaptor, meaning that if a bug is reintroduced that causes unwanted logging, we should be able to catch it both by the assertion in the test and by seeing the it in the console.

@Hakky54
Copy link
Contributor

Hakky54 commented Aug 31, 2023

I think it should be possible, if you are ok I would like to give it a shot. Can you point out which logs you still want to see and which should not appear?

@joc-a
Copy link
Collaborator Author

joc-a commented Aug 31, 2023

@Hakky54 If you change this line here to this fun <T> getOrNull(expression: Expression<T>): T? = if (hasValue(expression)) get(expression) else null, you should be able to see a warning in the console when running this test testNoWarningsOnLeftJoinRegression.

WARN Test worker Exposed:getInternal:57 - Column jointable.dataCol is marked as not null, has default db value, but returns null. Possible have to re-read it from DB.

This should be the only warning with nothing else.
If I keep the LogCaptor dependency and add the logback-test.xml as you suggested, I would no longer see that warning in the console.

@joc-a joc-a marked this pull request as ready for review August 31, 2023 22:35
@joc-a joc-a requested review from e5l and bog-walk August 31, 2023 22:35
Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check #1852, it looks much simpler

@joc-a
Copy link
Collaborator Author

joc-a commented Sep 5, 2023

Closing this in favour of #1852

@joc-a joc-a closed this Sep 5, 2023
@joc-a joc-a deleted the joc/fix-verbose-logging branch September 5, 2023 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants