protected void existingInit()

in contribs/KevinSteppe/CompositeRollingAppender.java [444:514]


	protected void existingInit() {

		curSizeRollBackups = 0;
		curTimeRollBackups = 0;

		//part A starts here
		String filter;
		if (staticLogFileName || !rollDate) {
			filter = baseFileName + ".*";
		}
		else {
			filter = scheduledFilename + ".*";
		}

		File f = new File(baseFileName);
		f = f.getParentFile();
		if (f == null)
		   f = new File(".");

		LogLog.debug("Searching for existing files in: " + f);
		String[] files = f.list();

		if (files != null) {
			for (int i = 0; i < files.length; i++) {
				if (!files[i].startsWith(baseFileName))
				   continue;

				int index = files[i].lastIndexOf(".");

				if (staticLogFileName) {
				   int endLength = files[i].length() - index;
				   if (baseFileName.length() + endLength != files[i].length()) {
					   //file is probably scheduledFilename + .x so I don't care
					   continue;
				   }
				}

				try {
					int backup = Integer.parseInt(files[i].substring(index + 1, files[i].length()));
					LogLog.debug("From file: " + files[i] + " -> " + backup);
					if (backup > curSizeRollBackups)
					   curSizeRollBackups = backup;
				}
				catch (Exception e) {
					//this happens when file.log -> file.log.yyyy-mm-dd which is normal
					//when staticLogFileName == false
					LogLog.debug("Encountered a backup file not ending in .x " + files[i]);
				}
			}
		}
		LogLog.debug("curSizeRollBackups starts at: " + curSizeRollBackups);
		//part A ends here

		//part B not yet implemented

		//part C
		if (staticLogFileName && rollDate) {
			File old = new File(baseFileName);
			if (old.exists()) {
				Date last = new Date(old.lastModified());
				if (!(sdf.format(last).equals(sdf.format(now)))) {
					scheduledFilename = baseFileName + sdf.format(last);
					LogLog.debug("Initial roll over to: " + scheduledFilename);
					rollOverTime();
				}
			}
		}
		LogLog.debug("curSizeRollBackups after rollOver at: " + curSizeRollBackups);
		//part C ends here

	}