private void createLogFiles() throws Exception {
try {
String configInfoPath = voltDbRootPath + File.separator + "config_log" + File.separator + "config.json";;
JSONObject jsonObject= Collector.parseJSONFile(configInfoPath);
JSONArray jsonArray = jsonObject.getJSONArray("log4jDst");
//maintain the file naming format
String fileNamePrefix = "volt-junit-fulllog.txt.";
String fileText = "This is a dummy log file.";
String workingDir = getWorkingDir(voltDbRootPath);
VoltFile logFolder = new VoltFile(workingDir + "/obj/release/testoutput/");
logFolder.mkdir();
for(File oldLogFile : logFolder.listFiles()) {
if(oldLogFile.getName().startsWith(fileNamePrefix)) {
oldLogFile.delete();
}
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String[] fileDates = new String[6];
Calendar cal, cal2;
cal = Calendar.getInstance();
cal2 = Calendar.getInstance();
for(int i=-1; i < 2; i++) {
cal.add(Calendar.DATE, -i-1);
fileDates[i+1] = formatter.format(cal.getTime());
}
cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -1);
cal2.set(cal.get(Calendar.YEAR), 11, 31);
fileDates[3] = formatter.format(cal2.getTime());
cal2.add(Calendar.DATE, -4);
fileDates[4] = formatter.format(cal2.getTime());
cal2 = Calendar.getInstance();
cal2.set(cal2.get(Calendar.YEAR), 0, 02);
fileDates[5] = formatter.format(cal2.getTime());
for(String fileDate: fileDates) {
VoltFile file = new VoltFile(logFolder, fileNamePrefix + fileDate);
file.createNewFile();
BufferedWriter writer = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
writer.write(fileText);
writer.close();
formatter.format(file.lastModified());
file.setLastModified(formatter.parse(fileDate).getTime());
JSONObject object = new JSONObject();
object.put("path", file.getCanonicalPath());
object.put("format", "'.'" + fileDate);
jsonArray.put(object);
}
FileOutputStream fos = new FileOutputStream(configInfoPath);
fos.write(jsonObject.toString(4).getBytes(Charsets.UTF_8));
fos.close();