开发者

Silencing Flyway -- a log4j problem

开发者 https://www.devze.com 2023-03-11 05:03 出处:网络
I\'ve written a wrapper around Flyway I call Nomad. I am well pleased with Flyway, save the incessant logging it performs outside of Maven. I created an issue here. Each user of Nomad must make their

I've written a wrapper around Flyway I call Nomad. I am well pleased with Flyway, save the incessant logging it performs outside of Maven. I created an issue here. Each user of Nomad must make their own configuration of log4j to silence Flyway. This is problematic if not done, for instance, during Spec testing. However, getting the configuration just right is a challeng开发者_开发百科e and, moreover, having to do this breaks the abstraction of my library.

My question is this: how can I permanently silence flyway so that any user of Nomad is not burdened with the task? I've found that this log4j.xml sometimes works:

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601} %t %-5p %c{1} - %m%n"/>
        </layout>
    </appender>

    <logger name="org.springframework" additivity="false">
        <level value="error"/>
        <appender-ref ref="console"/>
    </logger>

    <root>
        <priority value="error"/>
        <appender-ref ref="console"/>
    </root>
</log4j:configuration>

This stifles Flyway to the point of being helpful, rather than overly chatty. The misdirection is still broken, but not often.


The way you have done it in log4j.xml seems good. I don't see anything wrong.

Since the project uses Maven, I recommend you adding a property file instead log4j.properties, that you place that in src/main/resources

The contents can be:

log4j.rootCategory=DEBUG, stderr
log4j.appender.stderr=org.apache.log4j.ConsoleAppender
log4j.appender.stderr.target=System.err
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern=[%d] %-5p %c %x: %m%n

# Silence springframework messages.
org.springframework=ERROR

Perhaps that will work better with you. It becomes easier to manage too.


Flyway's only non-logging framework dependency is Spring. As Mohamed Mansour pointed out you can suppress all but the ERROR messages with a simple Log4J configuration setting.

For Spring (as pointed out by Mohamed Mansour):

org.springframework=ERROR

For Flyway:

com.googlecode.flyway=ERROR
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号