Log42 配置文件优化

yun-zuoyi
汪云昊 5 years ago
parent 06dcb22bad
commit d2bc1f287e

@ -5,32 +5,19 @@
<configuration status="WARN" monitorInterval="30" packages="cn.estsh.impp.framework.boot.log">
<Properties>
<Property name="log4j2.level" value="INFO"/>
<!-- 日志存放位置 -->
<Property name="logFileRootPath" value="../logs"/>
<!-- 日志输出格式 -->
<Property name="pattern">[%p] %d{yyyy-MM-dd HH:mm:ss-SSS} %l 信息:%m%n</Property>
<Property name="info_pattern">[%p] %d{yyyy-MM-dd HH:mm:ss-SSS} %c(%M:%L) 信息:%m%n</Property>
<Property name="system_log_pattern">[SYS-%p] %d{yyyy-MM-dd HH:mm:ss-SSS} 系统:%m ( %F -> %M:%L)%n</Property>
</Properties>
<appenders>
<ImppLog4j2Appender name="impp-log">
<!-- impp 日志拦截 -->
<ImppLog4j2Appender name="impp_log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %t [%c{1.}(%M:%L)] ==>> %msg%xEx"/>
</ImppLog4j2Appender>
<!--文件会打印出所有信息这个log每次运行程序会自动清空由append属性决定这个也挺有用的适合临时测试用-->
<RollingFile name="log" fileName="${logFileRootPath}/${project.name}.log" append="false"
filePattern="${logFileRootPath}/${project.name}-%d{yyyy-MM-dd}-warn-%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss-SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="3"/>
</RollingFile>
<!--这个输出控制台的配置-->
<console name="Console" target="SYSTEM_OUT" follow="true">
<!--控制台日志-->
<console name="console" target="SYSTEM_OUT" follow="true">
<PatternLayout>
<Pattern>${info_pattern}</Pattern>
</PatternLayout>
@ -39,11 +26,10 @@
<loggers>
<!-- 忽略 Swagger 格式化错误 -->
<logger name="io.swagger.models.parameters.AbstractSerializableParameter" level="ERROR" />
<logger name="io.swagger.models.parameters.AbstractSerializableParameter" level="ERROR"/>
<root level="${log4j2.level}">
<appender-ref ref="impp-log"/>
<appender-ref ref="log"/>
<appender-ref ref="Console"/>
<appender-ref ref="impp_log"/>
<appender-ref ref="console"/>
</root>
</loggers>
</configuration>

@ -9,43 +9,86 @@
<Property name="logFileRootPath" value="../logs"/>
<!-- 日志输出格式 -->
<Property name="pattern">[%p] %d{yyyy-MM-dd HH:mm:ss-SSS} %l 信息:%m%n</Property>
<Property name="info_pattern">[%p] %d{yyyy-MM-dd HH:mm:ss-SSS} %c(%M:%L) 信息:%m%n</Property>
<Property name="system_log_pattern">[SYS-%p] %d{yyyy-MM-dd HH:mm:ss-SSS} 系统:%m ( %F -> %M:%L)%n</Property>
<Property name="file_pattern">[%p] %d{yyyy-MM-dd HH:mm:ss-SSS} %-5level %class{36} %L %M - %msg%xEx%n</Property>
</Properties>
<appenders>
<!-- Impp 自定义 Appender 日志持久化 -->
<ImppLog4j2Appender name="impp-log">
<!-- impp 日志拦截 -->
<ImppLog4j2Appender name="impp_log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %t [%c{1.}(%M:%L)] ==>> %msg%xEx"/>
</ImppLog4j2Appender>
<!--文件会打印出所有信息这个log每次运行程序会自动清空由append属性决定这个也挺有用的适合临时测试用-->
<RollingFile name="log" fileName="${logFileRootPath}/${project.name}.log" append="false"
filePattern="${logFileRootPath}/${project.name}-%d{yyyy-MM-dd}-warn-%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss-SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
<!-- 应用日志文件-->
<RollingRandomAccessFile name="log_file"
fileName="${logFileRootPath}/${project.name}.log"
append="false" immediateFlush="false" bufferedIO="true" bufferSize="8192"
filePattern="${logFileRootPath}/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="${file_pattern}"/>
<Filters>
<ImppScheduleFilter onMatch="DENY" onMismatch="ACCEPT" />
</Filters>
<!-- 滚动策略 -->
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<!-- 定时删除 -->
<DefaultRolloverStrategy>
<Delete basePath="${logFileRootPath}" maxDepth="2">
<IfFileName glob="**/${project.name}**.log">
<IfLastModified age="7d"/>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
<!-- 应用调度日志文件-->
<RollingRandomAccessFile name="log_schedule_file"
fileName="${logFileRootPath}/${project.name}-schedule.log"
append="false" immediateFlush="false" bufferedIO="true" bufferSize="8192"
filePattern="${logFileRootPath}/$${date:yyyy-MM}/${project.name}-schedule-%d{yyyy-MM-dd}-%i.log">
<PatternLayout pattern="${file_pattern}"/>
<Filters>
<ImppScheduleFilter onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<!-- 滚动策略 -->
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="3"/>
</RollingFile>
<Console name="console" target="SYSTEM_OUT" follow="true">
<!--控制台只输出level及以上级别的信息-->
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
<!-- 定时删除 -->
<DefaultRolloverStrategy>
<Delete basePath="${logFileRootPath}" maxDepth="2">
<IfFileName glob="**/${project.name}-Schedule**.log">
<IfLastModified age="7d"/>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
<!--控制台日志-->
<console name="console" target="SYSTEM_OUT" follow="true">
<PatternLayout>
<Pattern>${info_pattern}</Pattern>
</PatternLayout>
</Console>
</console>
</appenders>
<loggers>
<!-- 忽略 Swagger 格式化错误 -->
<logger name="io.swagger.models.parameters.AbstractSerializableParameter" level="ERROR" />
<logger name="io.swagger.models.parameters.AbstractSerializableParameter" level="ERROR"/>
<root level="${log4j2.level}">
<appender-ref ref="log"/>
<!-- <appender-ref ref="impp-log"/>-->
<appender-ref ref="impp_log"/>
<appender-ref ref="console"/>
<appender-ref ref="log_schedule_file"/>
<appender-ref ref="log_file"/>
</root>
</loggers>
</configuration>
Loading…
Cancel
Save