springboot 配置log4j2 解决无法输出log 屏蔽tomcat启动debug日志

<?xml version="1.0" encoding="UTF-8"?>
<!-- status="error" log4j2把自身事件记录到控制台的配置,与下面root配置级别无关联
 设置debug级别以下,可以屏蔽tomcat启动多余debug日志-->
<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>
        <!-- additivity="false" 日志不会输出
			想要输出可以在当前标签中追加<appender-ref ref="debug_log" />
     		additivity="true"日志输出,根据<root></root>中appender-ref-->
		<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>
        <!-- 设置项目中dao层 -->
		<Logger name="com.mybatis.dao" level="debug" additivity="true">
		</Logger>
        <!-- level="trace"日志级别总开关, mybatis输出sql设置为debug
 			mybatis输出sql以及结果集设置true-->
		<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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值