log4j配置文件

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="off">
	<Properties>
		<!-- 日志存储路径 -->
		<Property name="baseDir">./logs</Property>
	</Properties>
	<CustomLevels>
		<CustomLevel name="AUDIT" intLevel="50" />
	</CustomLevels>
	
	<Appenders>
		<Console name="console" target="SYSTEM_OUT">
			<PatternLayout charset="UTF-8" pattern="[%-5p] [%d{HH:mm:ss}] %c - %m%n" />
		</Console>
		
		<!-- 自定义 -->
		<RollingFile name="RollingFileAUDIT" 
				fileName="${baseDir}/logservice-web/audit-log/audit-log.log" filePattern="${baseDir}/logservice-web/audit-log/audit-log-%i.log">
			<ThresholdFilter level="AUDIT" onMatch="ACCEPT" onMismatch="DENY" />
			<PatternLayout pattern="[%d{yyyy/MM/dd HH:mm:ssS}][%p][LOGSERVICE][日志系统]%m%n" />
			<Policies>
				<SizeBasedTriggeringPolicy size="10 MB" />
			</Policies>
			<!-- 保存最大文件个数 -->
			<DefaultRolloverStrategy max="50" />
		</RollingFile>
		
		<!--Trace级别日志输出-->
		<RollingFile name="system-trace"
				fileName="${baseDir}/logservice-web/trace.log" filePattern="${baseDir}/logservice-web/trace-%i.log">
			<Filters>
                <ThresholdFilter level="debug" onMatch="DENY" onMismatch="NEUTRAL"/>  
                <ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY" />
            </Filters>
			<PatternLayout charset="UTF-8" pattern="[%d{yyyy/MM/dd HH:mm:ssSSS}][%p][LOGSERVICE][日志系统][%l]%n%m%n" />
			<Policies>
				<!-- 日志文件大小 -->
				<SizeBasedTriggeringPolicy size="10 MB" />
			</Policies>
			<!-- 保存最大文件个数 -->
			<DefaultRolloverStrategy max="50" />
		</RollingFile>
		<!--Info级别日志输出-->
		<RollingFile name="system-info"
				fileName="${baseDir}/logservice-web/info.log" 
				filePattern="${baseDir}/logservice-web/info-%i.log">
			<Filters>
                <ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>  
                <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY" />
            </Filters>
			<PatternLayout charset="UTF-8" pattern="[%d{yyyy/MM/dd HH:mm:ssSSS}][%p][LOGSERVICE][日志系统][%l]%n%m%n" />
			<Policies>
				<SizeBasedTriggeringPolicy size="10 MB" />
			</Policies>
			<DefaultRolloverStrategy max="50" />
		</RollingFile>
		<!--Debug级别日志输出-->
		<RollingFile name="system-debug"
				fileName="${baseDir}/logservice-web/debug.log" filePattern="${baseDir}/logservice-web/debug-%i.log">
			<Filters>
                <ThresholdFilter level="info" onMatch="DENY" onMismatch="NEUTRAL"/>  
                <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY" />
            </Filters>
			<PatternLayout charset="UTF-8" pattern="[%d{yyyy/MM/dd HH:mm:ssSSS}][%p][LOGSERVICE][日志系统][%l]%n%m%n" />
			<Policies>
				<SizeBasedTriggeringPolicy size="10 MB" />
			</Policies>
			<DefaultRolloverStrategy max="50" />
		</RollingFile>
		<!--Error级别日志输出-->
		<RollingFile name="system-error"
				fileName="${baseDir}/logservice-web/error.log" filePattern="${baseDir}/logservice-web/error-%i.log">
			<Filters>
				<ThresholdFilter level="AUDIT" onMatch="DENY" onMismatch="NEUTRAL" />
                <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY" />
            </Filters>
			<PatternLayout charset="UTF-8" pattern="[%d{yyyy/MM/dd HH:mm:ssSSS}][%p][LOGSERVICE][日志系统][%l]%n%m%n" />
			<Policies>
				<SizeBasedTriggeringPolicy size="10 MB" />
			</Policies>
			<DefaultRolloverStrategy max="50" />
		</RollingFile>
	</Appenders>
<Loggers>
		<logger name="io.netty" level="INFO"></logger>
		<logger name="org.springframework" level="INFO"></logger>
		<logger name="org.elasticsearch" level="INFO"></logger>
		<root level="INFO">
			<appender-ref ref="console" />
			<appender-ref ref="system-info" />
			<appender-ref ref="system-trace" />
			<appender-ref ref="system-debug" />
			<appender-ref ref="system-error" />
			<appender-ref ref="RollingFileAUDIT" />
		</root>
	</Loggers>
</configuration>


相关推荐
NCIN EXPE4 天前
SpringBoot Test详解
spring boot·后端·log4j
polaris06304 天前
Spring Boot 项目开发流程全解析
java·spring boot·log4j
yoyo_zzm6 天前
SpringBoot Test详解
spring boot·后端·log4j
marsh02066 天前
36 openclaw单元测试框架:编写可维护的测试代码
ai·单元测试·log4j·编程·技术
醇氧6 天前
【学习】软件过程模型全解析:从瀑布到敏捷的演进之路
学习·log4j
WiChP10 天前
【V0.1B6】从零开始的2D游戏引擎开发之路
java·log4j·游戏引擎
__zRainy__11 天前
Node.js 日志选型指南:Winston vs Log4js 全方位对比与实战
node.js·log4j·winston
希望永不加班15 天前
SpringBoot 集成测试:@SpringBootTest 与 MockMvc
java·spring boot·后端·log4j·集成测试
Howrun77720 天前
C++ 项目测试全指南:从 0 基础到落地实操
开发语言·c++·log4j
admin and root22 天前
从资产收集FUZZ接口到SQL注入案例
网络·数据库·sql·安全·web安全·渗透测试·log4j