其他分享
首页 > 其他分享> > log4j2.xml

log4j2.xml

作者:互联网

 application.yml

# 日志配置
logging:
  config: classpath:log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>

<!--
 1. 日志级别: off > fatal > error > warn > info > debug > trace > all
 2. monitorInterval: 间隔秒数,自动检测和重载已修改的配置文件
-->
<Configuration status="info" monitorInterval="60">
    <Properties>
        <Property name="project.name">scooper-iflytek</Property>
        <Property name="log.dir">/icooper/log/${project.name}</Property>
        <Property name="pattern">%d{yyyy-MM-dd HH:mm:ss,SSS}[%-5p][%t] %m &lt;%M&gt;&lt;%F:%L&gt; %n</Property>
    </Properties>

    <Appenders>
        <Console name="console" target="SYSTEM_OUT">
            <ThresholdFilter level="debug" />
            <PatternLayout>
                <pattern>%d{yyyy-MM-dd HH:mm:ss,SSS}[${project.name}][%-5p][%t] %m &lt;%M&gt;&lt;%F:%L&gt; %n</pattern>
            </PatternLayout>
        </Console>

        <RollingRandomAccessFile name="rollingFileInfo" fileName="${log.dir}/info.log"
                                 filePattern="${log.dir}/info-%d{yyyyMMdd}-%i.log.zip">
            <Filters>
                <!-- 级别修改: info -> debug -->
                <ThresholdFilter level="info" />
            </Filters>
            <PatternLayout>
                <pattern>%d{yyyy-MM-dd HH:mm:ss,SSS}[%-5p][%t] %m %n</pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="100 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="20" >
                <Delete basePath="${log.dir}" >
                    <IfAccumulatedFileCount exceeds="100" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>

        <RollingRandomAccessFile name="rollingFileError" fileName="${log.dir}/error.log"
                                 filePattern="${log.dir}/error-%d{yyyyMMdd}-%i.log.zip">
            <Filters>
                <ThresholdFilter level="error" />
            </Filters>
            <PatternLayout>
                <pattern>${pattern}</pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="100 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="20" >
                <Delete basePath="${log.dir}" >
                    <IfAccumulatedFileCount exceeds="100" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingRandomAccessFile>
    </Appenders>

    <!--切换输出级别-->
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="console"/>
            <AppenderRef ref="rollingFileInfo"/>
            <AppenderRef ref="rollingFileError"/>
        </Root>
    </Loggers>
</Configuration>

标签:xml,%-,gt,HH,SSS,yyyy,lt,log4j2
来源: https://blog.csdn.net/piaomiao_/article/details/115523964