Skip to content
Snippets Groups Projects
Commit 73e7be5e authored by dgelessus's avatar dgelessus
Browse files

Refactor Log to be fully static

parent 45548edf
No related branches found
No related tags found
No related merge requests found
......@@ -10,14 +10,16 @@ import de.tlc4b.tlc.TLCResults;
import de.tlc4b.util.StopWatch;
import de.tlc4b.util.StopWatch.Watches;
public class Log {
public final class Log {
public static final String DELIMITER = ";";
private final List<String> fieldNames = new ArrayList<>();
private final List<String> fieldValues = new ArrayList<>();
private Log() {}
public static String getCSVString(TLC4B tlc4b, TLCResults tlcResults) {
List<String> fieldNames = new ArrayList<>();
List<String> fieldValues = new ArrayList<>();
public Log(TLC4B tlc4b, TLCResults tlcResults) {
fieldNames.add("Machine File");
String machineFile = tlc4b.getMainFile().getAbsolutePath();
fieldValues.add(machineFile);
......@@ -65,14 +67,11 @@ public class Log {
fieldNames.add("Trace File");
fieldValues.add(tlc4b.getTraceFile() != null ? tlc4b.getTraceFile().getAbsolutePath() : "");
}
public String getCSVString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fieldNames.size(); i++) {
sb.append(fieldNames.get(i)).append(DELIMITER).append(fieldValues.get(i)).append("\n");
}
return sb.toString();
}
}
......@@ -91,8 +91,7 @@ public class TLC4B {
results = new TLCResults(tlc4b.tlcOutputInfo);
results.evalResults();
tlc4b.printResults(results);
Log log = new Log(tlc4b, results);
tlc4b.createLogFile(log);
tlc4b.createLogFile(results);
} catch (NoClassDefFoundError e) {
printlnErr("Can not find TLC. The tlatools.jar must be included in the classpath.");
}
......@@ -213,8 +212,7 @@ public class TLC4B {
TLCResults results = new TLCResults(tlc4b.tlcOutputInfo);
results.evalResults();
tlc4b.printResults(results);
Log log = new Log(tlc4b, results);
tlc4b.createLogFile(log);
tlc4b.createLogFile(results);
System.exit(0);
}
......@@ -421,11 +419,12 @@ public class TLC4B {
}
}
private void createLogFile(Log log) {
private void createLogFile(TLCResults results) {
if (logFileString != null) {
String logCsvString = Log.getCSVString(this, results);
File logFile = new File(logFileString);
try (FileWriter fw = new FileWriter(logFile, true)) { // the true will append the new data
fw.write(log.getCSVString());
fw.write(logCsvString);
fw.close();
println("Log file: " + logFile.getAbsolutePath());
} catch (IOException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment