如何从另一个模块加载log4j2.xml配置文件

时间:2018-09-20 07:19:12

标签: spring-boot log4j2

我正在尝试将log4j2项目创建为lib模块

我的目标是每个App项目(A,B,C,...)都可以从log4j2模块导入log4j2.xml配置(使用相同的log4j2.xml删除重复的代码),但是没有发生log4j2未加载的情况。 / p>

enter image description here

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout
                    pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable" />
        </Console>

        <File name="JSONLogfileAppender" fileName="target/logfile.json">
            <JSONLayout compact="true" eventEol="true"/>
            <BurstFilter level="INFO" rate="2" maxBurst="10"/>
        </File>
        <Async name="AsyncAppender" bufferSize="80">
            <AppenderRef ref="JSONLogfileAppender"/>
        </Async>

        <Async name="AsyncAppenderRedis" bufferSize="80">
            <AppenderRef ref="REDIS"/>
        </Async>

        <RedisAppender name="REDIS"
                       key="log4j2-messages"
                       host="xx"
                       port="yy">
            <PatternLayout pattern="%level %msg"/>
            <RedisConnectionPoolConfig testWhileIdle="true"
                                       minEvictableIdleTimeMillis="60000"
                                       timeBetweenEvictionRunsMillis="30000"
                                       numTestsPerEvictionRun="-1"/>
            <RedisThrottlerConfig bufferSize="500"
                                  batchSize="100"
                                  flushPeriodMillis="1000"
                                  maxEventCountPerSecond="100"
                                  maxByteCountPerSecond="4194304"/>
        </RedisAppender>
    </Appenders>

    <Loggers>
        <!-- LOG everything at INFO level -->
        <Root level="info">
            <AppenderRef ref="AsyncAppenderRedis" />
            <AppenderRef ref="Console" />
            <AppenderRef ref="AsyncAppender" />
        </Root>

        <!-- LOG "net.mypackage" at TRACE level -->
        <Logger name="net.mypackage" level="trace"></Logger>
        <Logger name="org.springframework.cache" level="trace">
            <appender-ref ref="Console" />
        </Logger>
    </Loggers>

</Configuration>

0 个答案:

没有答案