Log4j2 - 2 appenderFile. I use only one ref, but two files are generated (One of them are empty)

52 views Asked by At

I have two appenders "RollingFile" like this :

<RollingFile name="fileDebug" fileName="${REP}/debug.log" filePattern="${REP}/debug-%d{yyyy-MM-dd}-%i.log">
    <Filters>                
        <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>            
    </Filters>
    <PatternLayout pattern="${LOG_PATTERN}"/>
    <Policies>
        <TimeBasedTriggeringPolicy/>
     </Policies>
    <DefaultRolloverStrategy max="2"/>
</RollingFile>

<RollingFile name="fileInfo" fileName="${REP}/info.log" filePattern="${REP}/info-%d{yyyy-MM-dd}-%i.log">
    <Filters>                
        <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>            
    </Filters>
    <PatternLayout pattern="${LOG_PATTERN}"/>
    <Policies>
        <TimeBasedTriggeringPolicy/>
    </Policies>
    <DefaultRolloverStrategy max="2"/>
</RollingFile>

And I call only one of them. For example

<Loggers>
    <Root level="all">
        <appender-ref ref="fileDebug"/>
    </Root>
</Loggers>

But, when I run my program, 2 files are generated : debug.log with logs and an empty info.log

How can I have only one file (debug.log) in this configuration ?

Many thanks

1

There are 1 answers

0
olivier P On

Finally, I make this configuration with the logging's level adjusted to ${LEVEL}

<RollingFile name="file" fileName="${REP}/file-${LEVEL}.log" filePattern="${REP}/file-${LEVEL}-%d{yyyy-MM-dd}-%i.log">
    <Filters>                
        <ThresholdFilter level="${LEVEL}" onMatch="ACCEPT" onMismatch="DENY"/>            
    </Filters>
    <PatternLayout pattern="${LOG_PATTERN}"/>
    <Policies>
        <TimeBasedTriggeringPolicy/>
    </Policies>
    <DefaultRolloverStrategy max="2"/>
</RollingFile>

<Loggers>
    <Root level="all">
        <appender-ref ref="file"/>
    </Root>
</Loggers>