You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Porfirio Partida (JIRA)" <ji...@apache.org> on 2013/09/18 20:31:54 UTC
[jira] [Comment Edited] (LOG4J2-385) Unable to roll log files
monthly
[ https://issues.apache.org/jira/browse/LOG4J2-385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13770290#comment-13770290 ]
Porfirio Partida edited comment on LOG4J2-385 at 9/18/13 6:31 PM:
------------------------------------------------------------------
org.apache.logging.log4j.core.appender.rolling.PatternProcessor
Method: getNextTime(long, int, boolean)
It has issues logging Monthly because it detects the next variables:
{code}
final Calendar currentCal = Calendar.getInstance();
currentCal.setTimeInMillis(current);
final Calendar cal = Calendar.getInstance();
cal.set(currentCal.get(Calendar.YEAR), 0, 1, 0, 0, 0); // inits with current year
cal.set(Calendar.MILLISECOND, 0);
....
if (frequency == RolloverFrequency.MONTHLY) {
increment(cal, Calendar.MONTH, increment, modulus);
nextTime = cal.getTimeInMillis();
cal.add(Calendar.MONTH, -1);
nextFileTime = cal.getTimeInMillis();
// Running on September the 17th (it doesn't matter the date)
// nextFileTime : 1357023600000 - Tue Jan 01 00:00:00 GMT-07:00 2013 //Only year is added
// nextTime : 1359702000000 - Fri Feb 01 00:00:00 GMT-07:00 2013 //Moving from Jan to Feb
return nextTime;
}
...
//Why is daily working then? because right after Monthly we have weekly (it should be failing as well) and then daily comes as this:
...
//Next line is going to point to current date to determine the very next lookup.
cal.set(Calendar.DAY_OF_YEAR, currentCal.get(Calendar.DAY_OF_YEAR));
if (frequency == RolloverFrequency.DAILY) {
increment(cal, Calendar.DAY_OF_YEAR, increment, modulus);
nextTime = cal.getTimeInMillis();
cal.add(Calendar.DAY_OF_YEAR, -1);
nextFileTime = cal.getTimeInMillis();
return nextTime;
}
...
{code}
In order to fix, we could move the line
{code} cal.set(Calendar.DAY_OF_YEAR, currentCal.get(Calendar.DAY_OF_YEAR)); {code}
to the top (before Year) and remove the elements as needed inside each if statement, ie:
- remove month, day, time inside year
- remove day and time inside month
- remove time inside daily
etc..
OR
we can set current month at month level and add the week at week level, like this:
{code}
if (frequency == RolloverFrequency.MONTHLY) {
+ cal.set(Calendar.MONTH, currentCal.get(Calendar.MONTH)); //moves the date to today's month.
increment(cal, Calendar.MONTH, increment, modulus);
nextTime = cal.getTimeInMillis();
cal.add(Calendar.MONTH, -1);
nextFileTime = cal.getTimeInMillis();
return nextTime;
}
if (frequency == RolloverFrequency.WEEKLY) {
+ cal.set(Calendar.WEEK_OF_YEAR, currentCal.get(Calendar.WEEK_OF_YEAR));//moves the week.
....
{code}
> Unable to roll log files monthly
> --------------------------------
>
> Key: LOG4J2-385
> URL: https://issues.apache.org/jira/browse/LOG4J2-385
> Project: Log4j 2
> Issue Type: Bug
> Components: Appenders
> Affects Versions: 2.0-beta8
> Environment: Java 1.7.0_25, Windows 7 64bit, IntelliJ IDEA 12 Ultimate
> Reporter: Ace Funk
>
> Attempting to use FastRollingFile appender and configure log file rollover to occur monthly. When filePattern="logs/app-%d{yyyy-MM}.log.gz" is used, at application start up an archive file is created immediately (app-2013-01.log.gz) even if no log previously existed. A log file is created, but only a single entry is made into the log.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org