I found a way by interposing so that others can also win.
To register sql queries, download Simple Logging Facade for Java ( download slf4j here )
Added the following to my classpath besides the usual mybatis, odbc and oracle jars
- log4j-xxxx.jar
- log4j-over-SLF4J-xxxx.jar
- log4j rolling appender.jar
- SLF4J-api-xxxx.jar
- SLF-log4j12-xxxx.jar
Note : xxxx is a suitable version here
and add the following lines to my log4j (see my question)
# logger debug log4j.logger.test.Log4jTestMyBatis=DEBUG, convert log4j.appender.convert = org.apache.log4j.ConsoleAppender log4j.appender.convert.layout=org.apache.log4j.PatternLayout log4j.appender.convert.layout.ConversionPattern=[%d{HH:mm:ss}] %-5p %c{3} %x - %m%n
Here is an example Groovy class that I used to test
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.ibatis.session.SqlSession; import org.apache.log4j.PropertyConfigurator; import com.abc.db.ConfigInfo; import com.abc.db.ConfigInfoExample; import com.abc.db.client.ConfigInfoMapper; import com.abc.db.init.DatabaseConnectivity; class Log4jTestMyBatis { static Logger logger = LoggerFactory.getLogger(Log4jTestMyBatis.class) static main(args) { PropertyConfigurator.configure(Log4jTestMyBatis.class.getResource("log4j.properties")); DatabaseConnectivity.init() SqlSession newABCSession = DatabaseConnectivity.getNewABCSessionFactory().openSession() ConfigInfoMapper mapper = newABCSession.getMapper(ConfigInfoMapper.class) ConfigInfoExample qExample = new ConfigInfoExample() qExample.createCriteria().andProjectIdEqualTo("0-12170") List<ConfigInfo> ctlist = mapper.selectByExample(qExample) logger.debug(ctlist.get(0).getCfgName()) newABCSession.close() logger.debug("debug") } }
source share