• Log4j2_学习_01_Log4j 2使用教程


     一、推荐使用的log4j2.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- 设置log4j2的自身log级别为warn -->
    <!-- OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
    <configuration status="WARN" monitorInterval="30">
        <properties>
            <property name="LOG_HOME">logs</property>
            <property name="FILE_NAME">info</property>
            <property name="FILE_NAME_WARN">warn</property>
            <property name="FILE_NAME_ERROR">error</property>
        </properties>
        <appenders>
            <console name="Console" target="SYSTEM_OUT">
                <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
            </console>
    
            <RollingFile name="RollingFileInfo" fileName="${LOG_HOME}/${FILE_NAME}.log"
                filePattern="${LOG_HOME}/$${date:yyyy-MM}/${FILE_NAME}-%d{yyyy-MM-dd HH-mm}-%i.log">
                <!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch) -->
                <Filters>
                    <ThresholdFilter level="INFO" />
                    <ThresholdFilter level="WARN" onMatch="DENY"
                        onMismatch="NEUTRAL" />
                </Filters>
                <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
                <Policies>
                    <TimeBasedTriggeringPolicy />
                    <SizeBasedTriggeringPolicy size="100 MB" />
                </Policies>
                <DefaultRolloverStrategy max="20" />
            </RollingFile>
    
            <RollingFile name="RollingFileWarn" fileName="${LOG_HOME}/${FILE_NAME_WARN}.log"
                filePattern="$${LOG_HOME}/$${date:yyyy-MM}/${FILE_NAME_WARN}-%d{yyyy-MM-dd HH-mm}-%i.log">
                <Filters>
                    <ThresholdFilter level="WARN" />
                    <ThresholdFilter level="ERROR" onMatch="DENY"
                        onMismatch="NEUTRAL" />
                </Filters>
                <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
                <Policies>
                    <TimeBasedTriggeringPolicy />
                    <SizeBasedTriggeringPolicy size="100 MB" />
                </Policies>
                <DefaultRolloverStrategy max="20" />
            </RollingFile>
    
            <RollingFile name="RollingFileError" fileName="${LOG_HOME}/${FILE_NAME_ERROR}.log"
                filePattern="${LOG_HOME}/$${date:yyyy-MM}/${FILE_NAME_ERROR}-%d{yyyy-MM-dd HH-mm}-%i.log">
                <ThresholdFilter level="ERROR" />
                <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
                <Policies>
                    <TimeBasedTriggeringPolicy />
                    <SizeBasedTriggeringPolicy size="100 MB" />
                </Policies>
                <DefaultRolloverStrategy max="20" />
            </RollingFile>
    
        </appenders>
    
        <loggers>
            <!--过滤掉spring和mybatis的一些无用的DEBUG信息 -->
            <logger name="org.springframework" level="INFO"></logger>
            <logger name="org.mybatis" level="INFO"></logger>
            <root level="all">
                <appender-ref ref="Console" />
                <appender-ref ref="RollingFileInfo" />
                <appender-ref ref="RollingFileWarn" />
                <appender-ref ref="RollingFileError" />
            </root>
        </loggers>
    
    </configuration>
    View Code

    二、参考文献

    1.LOG4J2 简明教程

    1.Log4j 2使用教程

    2.详解log4j2(上) - 从基础到实战

  • 相关阅读:
    beta阶段贡献分配实施
    Beta发布
    Beta发布——视频博客
    Scrum立会报告+燃尽图(Beta阶段第二周第七次)
    Beta发布——美工+文案
    Scrum立会报告+燃尽图(Beta阶段第二周第六次)
    Scrum立会报告+燃尽图(Beta阶段第二周第五次)
    Scrum立会报告+燃尽图(Beta阶段第二周第四次)
    Scrum立会报告+燃尽图(Beta阶段第二周第三次)
    20181011-1每周例行报告
  • 原文地址:https://www.cnblogs.com/shirui/p/7756742.html
Copyright © 2020-2023  润新知