1. 程式人生 > >log4j2 配置檔案log4j2.xml

log4j2 配置檔案log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<!-- Log4j 2.x 配置檔案。每30秒自動檢查和應用配置檔案的更新; -->
<Configuration status="warn" monitorInterval="30" strict="true" schema="Log4J-V2.2.xsd">
	<Appenders>
		<!-- 輸出到控制檯 -->
		<Console name="Console" target="SYSTEM_OUT">
			<!-- 需要記錄的級別 -->
			<!-- <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY" /> -->
			<!-- <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n" />
				-->
			
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS}|%5p|%F.%M:%L|%m%n" />
			
		</Console>

		<!-- 輸出到檔案,按天或者超過80MB分割 -->
		<RollingFile name="RollingFile" fileName="logs/platform.log"    filePattern="logs/$${date:yyyy-MM}/platform-%d{yyyy-MM-dd}-%i.log.gz">
			<!-- 需要記錄的級別 -->
			<!-- <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY" /> -->
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS}|%5p|%F.%M:%L|%m%n" />
			<Policies>
				<OnStartupTriggeringPolicy />
				<TimeBasedTriggeringPolicy />
				<SizeBasedTriggeringPolicy size="80 MB" />
			</Policies>
		</RollingFile>
	</Appenders>
	<Loggers>
		<Root level="info"> <!-- 全域性配置 -->
			<AppenderRef ref="Console" />
			<AppenderRef ref="RollingFile"/>
		</Root>
		<!-- 所有com.joyintech 包的 Log級別,方便除錯 -->
		<Logger name="com.joyintech" level="debug" additivity="false">
			<AppenderRef ref="Console" />
			<AppenderRef ref="RollingFile"/>
		</Logger>
		
		<!-- 單獨包的日誌配置-->
		<Logger name="org.springframework" level="debug" additivity="false">
			<AppenderRef ref="Console" />
			<AppenderRef ref="RollingFile"/>
		</Logger>
	</Loggers>
</Configuration>