MyBatis' logging implementation does not have an option to hide SQL, however, it would be possible to achieve it using a custom interceptor.
Assuming you are using the latest version of MyBatis, here is an example implementation.
package pkg;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.log4j.Logger;
@Intercepts({
@Signature(
type = Executor.class,
method = "update",
args = { MappedStatement.class, Object.class }),
@Signature(
type = Executor.class,
method = "query",
args = { MappedStatement.class, Object.class,
RowBounds.class, ResultHandler.class })
})
public class LogStatementIdInterceptor implements Interceptor {
private static final Logger logger = Logger.getLogger(LogStatementInterceptor.class);
@Override
public Object intercept(Invocation invocation) throws Throwable {
MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
logger.debug(ms.getId());
return invocation.proceed();
}
}
To register the interceptor, add the following entry to the XML config file.
<plugins>
<plugin interceptor="pkg.LogStatementIdInterceptor" />
</plugins>
With Java config, pass an instance of the interceptor to org.apache.ibatis.session.Configuration#addInterceptor().
And in the log4j.properties ...
log4j.logger.pkg.LogStatementIdInterceptor=DEBUG