I am looking for a rollover strategy when the current log (the active output target in manual terminology) does not fix the file name, but the template is specified or, more precisely, the same template as in the attribute filePattern.
I want to get a daily survey where today log, say log-2015-05-05.log,, and in the midnight structure just stops writing it and starts writing in log-2015-05-06.log. However AFAIK, the current configuration only allows
<RollingFile name="ROLFILE"
fileName="log.log"
filePattern="log-%d{yyyy-MM-dd}.log"
>
Setting the same value in the attribute fileNamedoes not work (leads to the fact that the file with sensitive letters is interpreted literally). I have not noticed a single example or SO question with such a dynamic value fileName. Please note that this fileName="log-${date:yyyy-MM-dd}.log"does not solve the problem, because the expression is evaluated only at startup, and events are still sent to the file, even if their timestamp does not match the expression.
I am moving from Log4j 1.2 to Log4j 2.2. In the old version, the required behavior is possible with
<appender name="ROLFILE" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="log-%d{yyyy-MM-dd}.log" />
</rollingPolicy>
...
I prefer to keep the current method as some log analysis tools rely on it. Is this possible in Log4j2? Thank.
source
share