<?xml version="1.0" encoding="UTF-8"?>
<configuration status="error" monitorInterval="30">
<appenders>
<Console name="stdout" target="SYSTEM_OUT">
<PatternLayout
pattern="%-20c - %m%n" />
</Console>
<RollingFile name="filedebug"
fileName="C:/***/***/**/**.log"
filePattern="C:/***/***/****/**.log.%d{yyyy-MM-dd}">
<PatternLayout charset="UTF-8" pattern="%d %p %x %c - %m%n" />
<Policies>
<SizeBasedTriggeringPolicy size="10MB" />
<TimeBasedTriggeringPolicy modulate="true" interval="1" />
</Policies>
<DefaultRolloverStrategy fileIndex="min" max="20" />
</RollingFile>
</appenders>
<loggers>
<Logger name="*.*.*.*" level="error" additivity="true">
</Logger>
<Logger name="*" level="debug" additivity="true">
</Logger>
<Logger name="*.*.*.*" level="debug" additivity="true">
</Logger>
<Logger name="org.springframework" level="error" additivity="true">
</Logger>
<Logger name="org.springframework.beans.factory.support.DefaultListableBeanFactory" level="error" additivity="true">
</Logger>
<Logger name="org.springframework.transaction.interceptor.TransactionInterceptor" level="error" additivity="true">
</Logger>
<Logger name="org.mybatis.spring" level="debug" additivity="true">
</Logger>
<Logger name="org.apache.ibatis.jdbc.ScriptRunner" level="debug" additivity="true">
</Logger>
<Logger name="java.sql" level="error" additivity="true">
</Logger>
<Logger name="java.sql.Connection" level="debug" additivity="true">
</Logger>
<Logger name="java.sql.Statement" level="debug" additivity="true">
</Logger>
<Logger name="java.sql.PreparedStatement" level="debug" additivity="true">
</Logger>
<Logger name="java.sql.ResultSet" level="debug" additivity="true">
</Logger>
<Logger name="org.apache" level="off">
</Logger>
<Logger name="com.mybatis.dao" level="debug" additivity="true">
</Logger>
<root level="trace">
<appender-ref ref="stdout" />
<appender-ref ref="filedebug" />
</root>
</loggers>
</configuration>
springboot 中配置log4j2 无法打印log
需要在mybatis-config.xml中追加
<setting name="logImpl" value="LOG4J2" />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL Map Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="true" />
<setting name="lazyLoadingEnabled" value="true" />
<setting name="defaultExecutorType" value="REUSE" />
<setting name="callSettersOnNulls" value="true"/>
<setting name="logImpl" value="LOG4J2" />
</settings>
</configuration>
application.yml配置
spring:
datasource:
platform: oracle
driver-class-name: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.1)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = 数据库名)))
username:
password:
mvc:
view:
suffix: .jsp
main:
allow-bean-definition-overriding: true
mybatis:
mapper-locations: classpath*:com.**.xml
config-location: classpath:mybatis-config.xml
logging:
config: classpath:log4j2.xml