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

Seeing DEBUG level logs after adding logcaptor dependency #47

Closed
joc-a opened this issue Aug 29, 2023 · 2 comments
Closed

Seeing DEBUG level logs after adding logcaptor dependency #47

joc-a opened this issue Aug 29, 2023 · 2 comments

Comments

@joc-a
Copy link

joc-a commented Aug 29, 2023

Describe the bug
I started seeing DEBUG level logging after adding the logcaptor dependency.
logger.isDebugEnabled is now returning true.

To Reproduce
I'm using slf4j and this is the log4j2.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n"/>
        </Console>
        <Async name="ASYNC" includeLocation="true">
            <AppenderRef ref="CONSOLE"/>
        </Async>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="ASYNC"/>
        </Root>
        <Logger name="LoggerName" level="info" additivity="false">
            <AppenderRef ref="ASYNC"/>
        </Logger>
    </Loggers>
</Configuration>

Expected behavior
How can I keep the same level of logging as before adding the dependency?

Screenshots
If applicable, add screenshots to help explain your problem.

Environmental Data:

  • Java Version
  • Maven Version
  • OS (Windows/Linux/MacOS)

Additional context
Add any other context about the problem here.

@Hakky54
Copy link
Owner

Hakky54 commented Aug 30, 2023

Do you mean that you are seeing these debug logs within your build output when running the tests?

@Hakky54
Copy link
Owner

Hakky54 commented Sep 6, 2023

We have resolved this issue together with the pull request for the exposed library here: JetBrains/Exposed#1852

The issue is not a bug but related to the underlying engine of LogCaptor which is outside of the control of LogCaptor itself. It is using Logback as SLF4J binding/implementation and Logback is using his own kind of logging configuration. So the log4j2.xml logger configuration is being ignored during the test resulting in showing also debug logs while previously disabled.

Solution is to add a logback-test.xml file in the test resources which is similar to the log4j2.xml configuration file. The file content of the logback-test.xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} %level %thread %logger{0}:%method:%line - %message %n</pattern>
        </encoder>
    </appender>
    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="CONSOLE"/>
        <includeCallerData>true</includeCallerData>
    </appender>

    <root level="INFO">
        <appender-ref ref="ASYNC" />
    </root>
    <logger name="Exposed" level="INFO" additivity="false">
        <appender-ref ref="ASYNC"/>
    </logger>
</configuration>

<!-- 19:57:29.845 DEBUG Test worker Exposed - DROP TABLE jointable -->

Please note that the above configuration is written for a specific project, if copied you need to adjust the logger name ad maybe ad additional loggers to further configure your logs. I am closing this issue, thank you @joc-a I think this is valuable for anyone who wil encounter the same issue.

@Hakky54 Hakky54 closed this as completed Sep 6, 2023
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

No branches or pull requests

2 participants