Log4j2 精典配置

19 篇文章 0 订阅

Configuration 节点上非常重要的一个属性 monitorinterval="10"表示每10秒检测1次配置文件的变化
配置文件的思想是将依赖jar包的关键日志信息输出到日志文件frame-output.log.%i
本工程下的日志输出到日志文件proj-output.log.%i

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE" monitorinterval="10">
    <Properties>
        <Property name="var.log.level">${mvn.log.level}</Property>
        <Property name="var.log.path.dir">${mvn.log.path}/f.alioo.online</Property>
        <Property name="var.output.pattern">[%-5p %d{yyyy-MM-dd HH:mm:ss.SSS}] [%t] [%l] %m%n</Property>
    </Properties>
    <Appenders>
        <Console name="stdout" target="SYSTEM_OUT">
            <PatternLayout pattern="${var.output.pattern}"/>
        </Console>
        <RollingRandomAccessFile bufferSize="1024" name="frame-output" fileName="${var.log.path.dir}/frame-output.log" filePattern="${var.log.path.dir}/frame-output.log.%i">
            <PatternLayout>
                <Pattern>${var.output.pattern}</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <DefaultRolloverStrategy max="5"/>
        </RollingRandomAccessFile>
        <RollingRandomAccessFile bufferSize="1024" name="o2o-api-monitor" fileName="${var.log.path.dir}/o2o-api-monitor.log" filePattern="${var.log.path.dir}/o2o-api-monitor.log.%i">
            <PatternLayout>
                <Pattern>[%-5p %d{yyyy-MM-dd HH:mm:ss.SSS}] %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <DefaultRolloverStrategy max="10"/>
        </RollingRandomAccessFile>
        <RollingRandomAccessFile bufferSize="1024" name="proj-output" fileName="${var.log.path.dir}/proj-output.log" filePattern="${var.log.path.dir}/proj-output.log.%i">
            <PatternLayout>
                <Pattern>${var.output.pattern}</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <AsyncRoot level="TRACE" includeLocation="true">
            <AppenderRef ref="stdout"/>
        </AsyncRoot>
        
        <!-- additivity为true时日志将会追加到控制台 -->
        <AsyncLogger name="org.springframework" level="DEBUG" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <!-- log4jdbc -->
        <AsyncLogger name="jdbc.sqltiming" level="INFO" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <!-- log4HibernateValidator -->
        <AsyncLogger name="org.apache.commons.validator.ValidatorResources" level="ERROR" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <!-- zookeeper -->
        <AsyncLogger name="org.apache.zookeeper" level="WARN" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <AsyncLogger name="org.apache.commons.beanutils" level="WARN" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <AsyncLogger name="org.apache.commons.digester" level="WARN" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <AsyncLogger name="org.apache.ibatis.logging.slf4j.Slf4jImpl" level="WARN" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <AsyncLogger name="org.springframework.ui.velocity" level="WARN" includeLocation="true" additivity="false">
            <AppenderRef ref="frame-output"/>
        </AsyncLogger>
        <!-- apache activemq -->
        <AsyncLogger name="org.apache.activemq" level="WARN" includeLocation="true" additivity="false">

        </AsyncLogger>

        <!-- project loggers begin -->
        <AsyncLogger name="com.alioo" level="${var.log.level}" includeLocation="true" additivity="true">
            <AppenderRef ref="proj-output"/>
        </AsyncLogger>
        <!-- project loggers end -->
    </Loggers>
</Configuration>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值