配置log4j2.xml输出MyBatis的SQL日志

前端之家收集整理的这篇文章主要介绍了配置log4j2.xml输出MyBatis的SQL日志前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在工作中,排查问题时难免需要输出MyBatis真正执行的sql及参数,需查看sql信息,如下是一种配置方法

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
	<Appenders>
		<Console name="console" target="SYSTEM_OUT">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{1}(%F:%L) - %m%n" />
		</Console>
		<RollingFile name="fixedTimeFileAppender" fileName="app/projectName.log"
			filePattern="app/projectName.log.%d{yyyy-MM-dd}.%i.log">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{1}(%L) - %m%n" />
			<Policies>
				<TimeBasedTriggeringPolicy />
				<SizeBasedTriggeringPolicy size="200 MB" />
			</Policies>
			<DefaultRolloverStrategy max="24" />
		</RollingFile>
		<RollingFile name="fixedTimeFilesqlAppender" fileName="app/projectName-sql.log"
			filePattern="app/projectName-sql.log.%d{yyyy-MM-dd}.%i.log">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5p %c{1}(%L) - %m%n" />
			<Policies>
				<TimeBasedTriggeringPolicy />
				<SizeBasedTriggeringPolicy size="200 MB" />
			</Policies>
			<DefaultRolloverStrategy max="24" />
		</RollingFile>
		
		<Async name="async" bufferSize="512">
			<AppenderRef ref="fixedTimeFileAppender" />
		</Async>
		<Async name="asyncsql" bufferSize="512" level="debug">
			<AppenderRef ref="fixedTimeFilesqlAppender" />
		</Async>
	</Appenders>
	<Loggers>
		<Logger name="cn.bijian" level="info" additivity="false">
			<AppenderRef ref="async" />
		</Logger>
		
		<Logger name="cn.bijian.projectName.dao" level="debug" additivity="false">
			<AppenderRef ref="asyncsql" />
		</Logger>
		
		<Root level="info">
			<AppenderRef ref="async" />
		</Root>
	</Loggers>
</Configuration>
原文链接:https://www.f2er.com/xml/294469.html

猜你在找的XML相关文章