The solution is: org.apache.ibatis.builder.xml.XMLConfigBuilder#parseConfiguration, move XMLConfigBuilder#loadCustomLogImpl method front of XMLConfigBuilder#loadCustomVfs method.
Add:
DefaultVFS#log is static final
field, and XMLConfigBuilder#loadCustomVfs will call Class#forName(java.lang.String, boolean, java.lang.ClassLoader)
.
MyBatis version
Most versions, including master (3.5.8)
Database vendor and version
It is not directly related, I chose MySQL
Test case or example project
MyBatis XML config:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
...
<settings>
<setting name="logImpl" value="org.apache.ibatis.logging.log4j.Log4jImpl"/>
<setting name="vfsImpl" value="org.apache.ibatis.io.JBoss6VFS,org.apache.ibatis.io.DefaultVFS"/>
</settings>
...
</configuration>
Steps to reproduce
- import slf4j and log4j (for example) dependency lib
- Customize logImpl to
org.apache.ibatis.logging.log4j.Log4jImpl
(by XML settinglogImpl
element), - Customize vfsImpls to
org.apache.ibatis.io.DefaultVFS
(by XML settingvfsImpl
element) - Then run by XML config, the log of
DefaultVFS
is slf4j impl logger (not customize logImpl )
Expected result
The Customize vfsImpls inner log filed is instantiate by customize logImpl.
Actual result
The Customize vfsImpls inner log filed is always instantiate by Slf4jImpl
.
Comment From: harawata
Hello @jinyahuan ,
Thank you for the report, but I don't think we can do this because the class specified in logImpl
needs to be loaded via the custom VFS.
Closing as won't fix.