spring-boot 配置log4j hibernate显示sql 格式化和sql参数
pom的第一个依赖里去掉 spring-boot-starter-logging
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
增加spring-boot-starter-log4j2 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
配置application.properties
logging.config=classpath:log4j2.xml
#logging.level.root=info
#logging.level.org.springframework.web= info
#logging.level.org.hibernate= info
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.show_sql=true
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
</Root>
<Logger name="org.hibernate.type.descriptor.sql" level="trace"
additivity="false">
<AppenderRef ref="Console" />
</Logger>
</Loggers>
</Configuration>