Skip to content

Commit

Permalink
fix verbosity reporting of logging writeShell
Browse files Browse the repository at this point in the history
allow window components to track output filename and verbosity level (remove getters and setters too)
  • Loading branch information
owlang committed Nov 29, 2023
1 parent 4499e7e commit b0180d1
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions src/main/java/scriptmanager/main/LogManagerWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import scriptmanager.util.FileSelection;
import scriptmanager.objects.LogItem;
import scriptmanager.objects.ToolDescriptions;
import scriptmanager.objects.Exceptions.ScriptManagerException;

/**
* Store, update, and manage the set of LogItems that make up a ScriptManager
Expand Down Expand Up @@ -77,10 +78,8 @@ public class LogManagerWindow extends JFrame {

private ArrayList<LogItem> logItems;
private Timestamp logStart;
private int verbosity = 0;

private File odir = null;
private String ofilename;

private boolean on = true;

Expand All @@ -93,7 +92,6 @@ public LogManagerWindow() {
// Initilize log timestamp
logStart = new Timestamp(new Date().getTime());
logItems = new ArrayList<LogItem>();
ofilename = logStart.toString().replace(' ', '_').replace(':', '-') + "_logfile.sh";
initialize();
}

Expand Down Expand Up @@ -200,7 +198,7 @@ public void actionPerformed(ActionEvent e) {
sl_pnlSettings.putConstraint(SpringLayout.NORTH, txtOutputFilename, 0, SpringLayout.NORTH, lblFileSeparator);
sl_pnlSettings.putConstraint(SpringLayout.WEST, txtOutputFilename, 10, SpringLayout.EAST, lblFileSeparator);
sl_pnlSettings.putConstraint(SpringLayout.EAST, txtOutputFilename, -10, SpringLayout.EAST, pnl_Settings);
txtOutputFilename.setText(getFilename());
txtOutputFilename.setText(logStart.toString().replace(' ', '_').replace(':', '-') + "_logfile.sh");
pnl_Settings.add(txtOutputFilename);
txtOutputFilename.setColumns(100);

Expand All @@ -211,6 +209,8 @@ public void actionPerformed(ActionEvent e) {
public void actionPerformed(ActionEvent e) {
try {
writeLogShell();
} catch (ScriptManagerException sme) {
JOptionPane.showMessageDialog(null, sme.getMessage());
} catch (IOException ioe) {
JOptionPane.showMessageDialog(null, ioe.getMessage());
}
Expand Down Expand Up @@ -289,15 +289,11 @@ public void drawTable() {
public ArrayList<LogItem> getLogItems() { return logItems; }
public LogItem getLogItem(int i) { return logItems.get(i); }
public Timestamp getLogStart() { return logStart; }
public int getVerbosity() { return verbosity; }
public String getFilename() { return ofilename; }
public File getOutputDirectory() { return odir; }

// Setters
public void setToggleOn(boolean toggle) { on = toggle; }
public void setLogStart(Timestamp time) { logStart = time; }
public void setVerbosity(int v) { verbosity = v; }
public void setFilename(String o) { ofilename = o; }
public void setOutputDirectory(File o) { odir = o; }

// Status - getters, setters, and Comparators
Expand Down Expand Up @@ -333,25 +329,44 @@ public void removeLogItems(int[] r_idxs) {
}
}

/**
* Get the verbosity value from the radio buttons
*
* @return verbosity level (1, 2, or 3)
*/
public short getLogVerbosity() throws ScriptManagerException {
if (verbosity1.isSelected()) {
return 1;
} else if (verbosity2.isSelected()) {
return 2;
} else if (verbosity3.isSelected()) {
return 3;
}
throw new ScriptManagerException("Unrecognized verbosity level. This should never throw");
}

/**
* Write the contents of the log as a shell script
*
* @throws IOException Invalid file or parameters
*/
public void writeLogShell() throws IOException {
public void writeLogShell() throws IOException, ScriptManagerException {
// Create File & initialize stream
PrintStream OUT = new PrintStream(new File(OUT_DIR + File.separator + ofilename));
PrintStream OUT = new PrintStream(new File(OUT_DIR + File.separator + txtOutputFilename.getText()));

// Determine verbosity of output
short verbosity = getLogVerbosity();

// Write Header (V=1+)
OUT.println("# VERSION\t" + ToolDescriptions.VERSION);
OUT.println("# VERSION\t" + ToolDescriptions.VERSION + "\tVerbosity Level:" + verbosity);
OUT.println("SCRIPTMANAGER=/path/to/ScriptManager.jar");
OUT.println("PICARD=/path/to/picard.jar");
OUT.println();

// Write LogInfo start time (V=1+)
OUT.println("# Log start time: " + logStart.toString());

// Sort LogItems for writing--not needed unless fireproperty adding out of order
// Add later: Sort LogItems for writing--not needed unless fireproperty adding out of order

// Record each LogItem
for (int i = 0; i<logItems.size(); i++) {
Expand All @@ -364,16 +379,19 @@ public void writeLogShell() throws IOException {
}

// Write LogItem command string (V=1+)
if (item.getStopTime()==null) {
OUT.print("# ");
}
OUT.println(item.getCommand());

if(verbosity>=2) {
// Write LogItem status (V=2+)
OUT.println("# " + item.getStatus());
OUT.println("# Exit status: " + item.getStatus());
// Write LogItem end time (V=2+)
OUT.println("# " + item.getStopTime().toString());
OUT.println(item.getStopTime()==null ? "#Incomplete" : "# " + item.getStopTime().toString());
// Write LogItem runtime (V=3+)
if(verbosity>=3) {
OUT.println("# Runtime: " + (item.getStopTime().getTime() - item.getStartTime().getTime()));
OUT.println(item.getStopTime()==null ? "# Runtime: -" : "# Runtime: " + (item.getStopTime().getTime() - item.getStartTime().getTime()));
}
}
// TODO: Write Toggle Log info
Expand Down

0 comments on commit b0180d1

Please sign in to comment.