• log4j配置参考


    ----------log4j配置参考

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!-- Bezaleel's comments downstairs. -->
    <!-- monitorInterval: refresh config interval (seconds) -->
    <configuration status="WARN" monitorInterval="300">
        <appenders>
            <!-- Console -->
            <Console name="Console" target="SYSTEM_OUT">
                <PatternLayout charset="UTF-8"
                    pattern="[%5.5p][%d{yyyy-MM-dd HH:mm:ss.SSS}][%25.25t][%l] - %m %ex %n" />
            </Console>
            <!-- RootLog -->
            <RollingFile name="RootLog" fileName="${sys:app.log.output}/root.log"
                filePattern="${sys:app.log.output}/${date:yyyy-MM}/root-%d{yyyy-MM-dd-HH}.%i.log.gz"
                ignoreExceptions="false">
                <PatternLayout charset="UTF-8"
                    pattern="[%5.5p][%d{yyyy-MM-dd HH:mm:ss.SSS}][%25.25t][%l] - %m %ex %n" />
                <Policies>
                    <!-- Rolling once per 1hours. -->
                    <TimeBasedTriggeringPolicy interval="1"
                        modulate="true" />
                    <!-- Rolling when reach 10MB per file. -->
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <!-- max : how many files hold? 1hour * 24 * 30 = 720. So we config 720 
                    to hold files in a month. -->
                <DefaultRolloverStrategy max="720" />
            </RollingFile>
            <!-- MxLog -->
            <RollingFile name="MxLog" fileName="${sys:app.log.output}/mx.log"
                filePattern="${sys:app.log.output}/${date:yyyy-MM}/mx-%d{yyyy-MM-dd}.%i.log.gz"
                ignoreExceptions="false">
                <PatternLayout charset="UTF-8"
                    pattern="[%5.5p][%d{yyyy-MM-dd HH:mm:ss.SSS}][%25.25t][%l] - %m %ex %n" />
                <Policies>
                    <TimeBasedTriggeringPolicy interval="1"
                        modulate="true" />
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <DefaultRolloverStrategy max="720" />
            </RollingFile>
            <!-- DscommLog -->
            <RollingFile name="DscommLog" fileName="${sys:app.log.output}/dscomm.log"
                filePattern="${sys:app.log.output}/${date:yyyy-MM}/dscomm-%d{yyyy-MM-dd}.%i.log.gz"
                ignoreExceptions="false">
                <PatternLayout charset="UTF-8"
                    pattern="[%5.5p][%d{yyyy-MM-dd HH:mm:ss.SSS}][%25.25t][%l] - %m %ex %n" />
                <Policies>
                    <TimeBasedTriggeringPolicy interval="1"
                        modulate="true" />
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <DefaultRolloverStrategy max="720" />
            </RollingFile>
            <!-- SpringSecurityLog -->
            <RollingFile name="SpringSecurityLog" fileName="${sys:app.log.output}/springsecurity.log"
                filePattern="${sys:app.log.output}/${date:yyyy-MM}/springsecurity-%d{yyyy-MM-dd}.%i.log.gz"
                ignoreExceptions="false">
                <PatternLayout charset="UTF-8"
                    pattern="[%5.5p][%d{yyyy-MM-dd HH:mm:ss.SSS}][%25.25t][%l] - %m %ex %n" />
                <Policies>
                    <TimeBasedTriggeringPolicy interval="1"
                        modulate="true" />
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <DefaultRolloverStrategy max="720" />
            </RollingFile>
            <!-- StrutsLog -->
            <RollingFile name="StrutsLog" fileName="${sys:app.log.output}/struts2.log"
                filePattern="${sys:app.log.output}/${date:yyyy-MM}/struts2-%d{yyyy-MM-dd}.%i.log.gz"
                ignoreExceptions="false">
                <PatternLayout charset="UTF-8"
                    pattern="[%5.5p][%d{yyyy-MM-dd HH:mm:ss.SSS}][%25.25t][%l] - %m %ex %n" />
                <Policies>
                    <TimeBasedTriggeringPolicy interval="1"
                        modulate="true" />
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <DefaultRolloverStrategy max="720" />
            </RollingFile>
            
            <Async name="org.mx" includeLocation="true">
                <AppenderRef ref="Console" />
                <AppenderRef ref="MxLog" />
            </Async>
            <Async name="com.dscomm" includeLocation="true">
                <AppenderRef ref="Console" />
                <AppenderRef ref="DscommLog" />
            </Async>
            <Async name="org.springframework.security" includeLocation="true">
                <AppenderRef ref="Console" />
                <AppenderRef ref="SpringSecurityLog" />
            </Async>
            <Async name="org.apache.struts2" includeLocation="true">
                <AppenderRef ref="Console" />
                <AppenderRef ref="StrutsLog" />
            </Async>
            <Async name="app.root" includeLocation="true">
                <AppenderRef ref="Console" />
                <AppenderRef ref="RootLog" />
            </Async>
        </appenders>
    
        <loggers>
            <logger name="org.mx.kernel" level="info" additivity="false">
                <appender-ref ref="org.mx" />
            </logger>
            <logger name="com.dscomm" level="info" additivity="false">
                <appender-ref ref="com.dscomm" />
            </logger>
            <logger name="org.springframework.security" level="info" additivity="false">
                <appender-ref ref="org.springframework.security" />
            </logger>
            <logger name="org.apache.struts2" level="info" additivity="false">
                <appender-ref ref="org.apache.struts2" />
            </logger>
            <logger name="com.opensymphony.xwork2" level="info" additivity="false">
                <appender-ref ref="org.apache.struts2" />
            </logger>
            <root level="warn">
                <AppenderRef ref="app.root" />
            </root>
        </loggers>
    </configuration>

     log4j2配置参考:

    <configuration status="off">
        <Properties>
            <!-- 日志存储路径 -->
            <Property name="baseDir">${sys:catalina.home}/logs/ds-plan-web</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}/audit-log/audit-log.log" filePattern="${baseDir}/audit-log/audit-log-%i.log">
                <ThresholdFilter level="AUDIT" onMatch="ACCEPT" onMismatch="DENY" />
                <PatternLayout pattern="[%d{yyyy/MM/dd HH:mm:ssS}][%p]%m%n" />
                <Policies>
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <!-- 保存最大文件个数 -->
                <DefaultRolloverStrategy max="50" />
            </RollingFile>
            
            <!--Trace级别日志输出-->
            <RollingFile name="system-trace"
                    fileName="${baseDir}/trace.log" filePattern="${baseDir}/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][%l]%n%m%n" />
                <Policies>
                    <!-- 日志文件大小 -->
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <!-- 保存最大文件个数 -->
                <DefaultRolloverStrategy max="50" />
            </RollingFile>
            <!--Info级别日志输出-->
            <RollingFile name="system-info"
                    fileName="${baseDir}/info.log" filePattern="${baseDir}/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][%l]%n%m%n" />
                <Policies>
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <DefaultRolloverStrategy max="50" />
            </RollingFile>
            <!--Debug级别日志输出-->
            <RollingFile name="system-debug"
                    fileName="${baseDir}/debug.log" filePattern="${baseDir}/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][%l]%n%m%n" />
                <Policies>
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <DefaultRolloverStrategy max="50" />
            </RollingFile>
            <!--Error级别日志输出-->
            <RollingFile name="system-error"
                    fileName="${baseDir}/error.log" filePattern="${baseDir}/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][%l]%n%m%n" />
                <Policies>
                    <SizeBasedTriggeringPolicy size="10 MB" />
                </Policies>
                <DefaultRolloverStrategy max="50" />
            </RollingFile>
        </Appenders>
        
        <Loggers>
            <root level="trace">
                <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>

    Log4j2自动清理历史日志

    https://segmentfault.com/a/1190000021221916?utm_source=tag-newest

  • 相关阅读:
    线程池略略观
    spring-mvc的工作原理
    openstack cinder-backup流程与源码分析
    为何说只有 1 种实现线程的方法?
    经典排序算法原理解析与优劣对比
    Java中List和ArrayList的区别
    openstack-taskflow 组件记录
    递归:如何利用递归求解汉诺塔问题?
    登录MySQL提示ERROR 1045 (28000)错误解决方法
    回归JavaScript基础(九)
  • 原文地址:https://www.cnblogs.com/Alwaysbecoding/p/12409497.html
Copyright © 2020-2023  润新知