int computeCheckPeriod() { CalendarRollingCalendar rollingCalendar = new CalendarRollingCalendar(gmtTimeZone, Locale.ENGLISH); // set sate to 1970-01-01 00:00:00 GMT Date epoch = new Date(0); if (datePattern != null) { for (int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern); simpleDateFormat.setTimeZone(gmtTimeZone); // do all date // formatting in GMT String r0 = simpleDateFormat.format(epoch); rollingCalendar.setType(i); Date next = new Date(rollingCalendar.getNextCheckMillis(epoch)); String r1 = simpleDateFormat.format(next); // logger.info("Type = "+i+", r0 = "+r0+", r1 = "+r1); if (r0 != null && r1 != null && !r0.equals(r1)) { return i; } } } return TOP_OF_TROUBLE; // Deliberately head for trouble... }
/** * This method differentiates RollingFileAppender from its super class. * * @since 0.9.0 */ protected void subAppend(LoggingEvent event) { long n = System.currentTimeMillis(); if (n >= nextCheck) { now.setTime(n); nextCheck = rc.getNextCheckMillis(now); try { rollOver(DailyRollingFileType); } catch (IOException ioe) { LogLog.error("rollOver() failed.", ioe); } } else if ((fileName != null) && ((CountingQuietWriter) qw).getCount() >= maxFileSize) { try { rollOver(RollingFileType); } catch (IOException ioe) { LogLog.error("rollOver() failed.", ioe); } } super.subAppend(event); }
public void activateOptions() { if (datePattern != null && name != null) { now.setTime(System.currentTimeMillis()); sdf = new SimpleDateFormat(datePattern); int type = computeCheckPeriod(); printPeriodicity(type); rc.setType(type); fileName = this.buildLogFilePathAnddeleteTimeoutFile(-1); File file = new File(fileName); // Strfilename = String.format("[%s]%s_%d", // sdf.format(now),Strfilename,1); scheduledDate = sdf.format(new Date(file.lastModified())); /* * scheduledFilename = String.format("[%s]%s.%s", sdf.format(new * Date( file.lastModified())), name, extname); */ // Date(file.lastModified())); } else { LogLog.error("Either File or DatePattern options are not set for appender [" + name + "]."); } super.activateOptions(); }