Search code examples
sqlhibernateloggingwildfly-11

Log org.hibernate.SQL in other .log file / Wildfly 11


I have this standalone.xml configuration in a subsystem:

<subsystem xmlns="urn:jboss:domain:logging:3.0">
    <console-handler name="CONSOLE">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>
        </formatter>
    </console-handler>
    <periodic-rotating-file-handler name="FILE">
        <formatter>
            <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>
        </formatter>
        <file relative-to="jboss.server.log.dir" path="server.log"/>
        <suffix value=".yyyy-MM-dd"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <periodic-rotating-file-handler name="CMP">
        <formatter>
            <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>
        </formatter>
        <file relative-to="jboss.server.log.dir" path="CMP.log"/>
        <suffix value=".yyyy-MM-dd"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <logger category="org.hibernate.SQL">
        <level name="DEBUG"/>
        <handlers>
            <handler name="CMP"/>
        </handlers>
    </logger>
    <root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="CONSOLE"/>
            <handler name="FILE"/>
        </handlers>
    </root-logger>
</subsystem>

When I run the application, it prints the org.hibernate.SQL (SQL queries for example) in both files, but I want to it prints the org.hibernate.SQL only in CMP.log file.

How can I exclude org.hibernate.SQL writes from server.log and print it only in CMP.log file?


Solution

  • You need to set the use-parent-handlers to false on the org.hibernate.SQL logger. With CLI you'd do something like:

    /subsystem=logging/logger=org.hibernate.SQL:write-attribute(name=use-parent-handlers, value=false)