Logging SQL-Statements with IBatis on Wildfly

Depending on what you want to see, you can enable logging for iBATIS in your logging configuration like this:

log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG

iBATIS uses its own logging implementation, which will forward entries to the first one of the following frameworks depending on the classes found on the classpath:

  • Commons Loggin
  • log4j
  • java util logger (jul)

If you use log4j for example, you will have a class org.apache.log4j.Logger on the classpath and iBATIS binds to it for logging.

WildFly comes with its own logging infrastructure and will create a bridges to the frameworks listed above. As iBATIS first checks for Commons Logging, it binds to the bridge wildfly provides and ignores any log4j configuration.

To solve that, you can change logging configuration in WildFly or disable WildFlys logging support in the jboss-deployment-structure.xml that is placed into the WEB-INF folder:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name="org.apache.commons.logging" />
      <module name="org.apache.log4j" />
      <module name="org.jboss.logging" />
      <module name="org.jboss.logging.jul-to-slf4j-stub" />
      <module name="org.jboss.logmanager" />
      <module name="org.jboss.logmanager.log4j" />
      <module name="org.slf4j" />
      <module name="org.slf4j.impl" />
    </exclusions>
    <exclude-subsystems>
      <subsystem name="logging" />
    </exclude-subsystems>
  </deployment>
</jboss-deployment-structure>