springboot 自带 日志打印 logback 如果使用log4j2 可能回抛出
Logging system failed to initialize using configuration from 'classpath:log4j2.xml'
java.lang.IllegalStateException: Logback configuration error detected:
解决办法也是百度来的 但是忘了是那个网址了 只让你 忽略一个
配置xml 时候 spring-boot-starter-web 也要忽略jar包 mybatis-spring-boot-starter 也要忽略jar包
说还有 加载顺序问题 如果在头忽略就可以下面不写 我没配置成功
pom.xml 部分代码如下
<!-- spring boot的相关启动 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 去掉默认的,不然log4j2没效果 -->
<!--去除springboot对logback的依赖 -->
<exclusions>
<exclusion>
<artifactId>logback-access</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>logback-core</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
<!-- spring boot整合mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<!-- 打印日志 log4j2 需要 是排除多余的jar包 springboot 默认使用logback log4j引入时候需要排除 -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<version>1.3.0</version>
</dependency>
<!-- log4j -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
配置log4j2 控制台打印sql语句
src/main/resource 下创建 (log4j2.xml 配置 不是全的 我就是想看个sql 不想要那么多配置 配置了好多都失败了 也只配置了properties文件 不是好使 现在不清楚到底那个是好使了 就全都配置)
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" monitorInterval="1800">
<appenders>
<Console name="consolePrint" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</appenders>
<loggers>
<!-- 将业务dao接口填写进去,并用控制台输出即可 -->
<logger name="example.moudels.*.mapper" level="DEBUG" additivity="false">
<appender-ref ref="consolePrint"/>
</logger>
<root level="info">
<appender-ref ref="consolePrint" />
</root>
</loggers>
</Configuration>
application.properties文件添加
logging.config=classpath:log4j2.xml
#levle后面的是你的mapper 接口的包名是dao层的dao接口 不是mapper.xml文件他俩可以放到一起的但是有的单独配置出来
logging.level.example.moudels.*.mapper=debug
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl