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>


相关推荐
知初~21 小时前
SpringBoot3
java·spring boot·spring·log4j·maven
LXMXHJ1 天前
Java-日志-Slf4j-Log4j-logback
java·log4j·logback
NullPointerExpection2 天前
java 中 main 方法使用 KafkaConsumer 拉取 kafka 消息如何禁止输出 debug 日志
java·kafka·log4j·slf4j
大强的博客5 天前
《Vue3实战教程》35:Vue3测试
log4j
123yhy传奇5 天前
【学习总结|DAY028】后端Web实战(部门管理)
java·学习·mysql·log4j·maven·mybatis·web
不灭锦鲤7 天前
buuctf漏洞复现之log4j
log4j
Kobebryant-Manba9 天前
单元测试学习2.0+修改私有属性
java·单元测试·log4j
董可伦9 天前
log4j 单独设置某个类或者某个包的级别
log4j
五月天的尾巴10 天前
log4j2的Strategy、log4j2的DefaultRolloverStrategy、删除过期文件
log4j·删除过期文件
编码浪子11 天前
构建一个rust生产应用读书笔记7-确认邮件3
log4j