'Log4j2 - 2 appenderFile. I use only one ref, but two files are generated (One of them are empty)
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
Solution 1:[1]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | olivier P |
