Skip to content

Commit b0180d1

Browse files
committed
fix verbosity reporting of logging writeShell
allow window components to track output filename and verbosity level (remove getters and setters too)
1 parent 4499e7e commit b0180d1

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

src/main/java/scriptmanager/main/LogManagerWindow.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import scriptmanager.util.FileSelection;
3737
import scriptmanager.objects.LogItem;
3838
import scriptmanager.objects.ToolDescriptions;
39+
import scriptmanager.objects.Exceptions.ScriptManagerException;
3940

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

7879
private ArrayList<LogItem> logItems;
7980
private Timestamp logStart;
80-
private int verbosity = 0;
8181

8282
private File odir = null;
83-
private String ofilename;
8483

8584
private boolean on = true;
8685

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

@@ -200,7 +198,7 @@ public void actionPerformed(ActionEvent e) {
200198
sl_pnlSettings.putConstraint(SpringLayout.NORTH, txtOutputFilename, 0, SpringLayout.NORTH, lblFileSeparator);
201199
sl_pnlSettings.putConstraint(SpringLayout.WEST, txtOutputFilename, 10, SpringLayout.EAST, lblFileSeparator);
202200
sl_pnlSettings.putConstraint(SpringLayout.EAST, txtOutputFilename, -10, SpringLayout.EAST, pnl_Settings);
203-
txtOutputFilename.setText(getFilename());
201+
txtOutputFilename.setText(logStart.toString().replace(' ', '_').replace(':', '-') + "_logfile.sh");
204202
pnl_Settings.add(txtOutputFilename);
205203
txtOutputFilename.setColumns(100);
206204

@@ -211,6 +209,8 @@ public void actionPerformed(ActionEvent e) {
211209
public void actionPerformed(ActionEvent e) {
212210
try {
213211
writeLogShell();
212+
} catch (ScriptManagerException sme) {
213+
JOptionPane.showMessageDialog(null, sme.getMessage());
214214
} catch (IOException ioe) {
215215
JOptionPane.showMessageDialog(null, ioe.getMessage());
216216
}
@@ -289,15 +289,11 @@ public void drawTable() {
289289
public ArrayList<LogItem> getLogItems() { return logItems; }
290290
public LogItem getLogItem(int i) { return logItems.get(i); }
291291
public Timestamp getLogStart() { return logStart; }
292-
public int getVerbosity() { return verbosity; }
293-
public String getFilename() { return ofilename; }
294292
public File getOutputDirectory() { return odir; }
295293

296294
// Setters
297295
public void setToggleOn(boolean toggle) { on = toggle; }
298296
public void setLogStart(Timestamp time) { logStart = time; }
299-
public void setVerbosity(int v) { verbosity = v; }
300-
public void setFilename(String o) { ofilename = o; }
301297
public void setOutputDirectory(File o) { odir = o; }
302298

303299
// Status - getters, setters, and Comparators
@@ -333,25 +329,44 @@ public void removeLogItems(int[] r_idxs) {
333329
}
334330
}
335331

332+
/**
333+
* Get the verbosity value from the radio buttons
334+
*
335+
* @return verbosity level (1, 2, or 3)
336+
*/
337+
public short getLogVerbosity() throws ScriptManagerException {
338+
if (verbosity1.isSelected()) {
339+
return 1;
340+
} else if (verbosity2.isSelected()) {
341+
return 2;
342+
} else if (verbosity3.isSelected()) {
343+
return 3;
344+
}
345+
throw new ScriptManagerException("Unrecognized verbosity level. This should never throw");
346+
}
347+
336348
/**
337349
* Write the contents of the log as a shell script
338350
*
339351
* @throws IOException Invalid file or parameters
340352
*/
341-
public void writeLogShell() throws IOException {
353+
public void writeLogShell() throws IOException, ScriptManagerException {
342354
// Create File & initialize stream
343-
PrintStream OUT = new PrintStream(new File(OUT_DIR + File.separator + ofilename));
355+
PrintStream OUT = new PrintStream(new File(OUT_DIR + File.separator + txtOutputFilename.getText()));
356+
357+
// Determine verbosity of output
358+
short verbosity = getLogVerbosity();
344359

345360
// Write Header (V=1+)
346-
OUT.println("# VERSION\t" + ToolDescriptions.VERSION);
361+
OUT.println("# VERSION\t" + ToolDescriptions.VERSION + "\tVerbosity Level:" + verbosity);
347362
OUT.println("SCRIPTMANAGER=/path/to/ScriptManager.jar");
348363
OUT.println("PICARD=/path/to/picard.jar");
349364
OUT.println();
350365

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

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

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

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

369387
if(verbosity>=2) {
370388
// Write LogItem status (V=2+)
371-
OUT.println("# " + item.getStatus());
389+
OUT.println("# Exit status: " + item.getStatus());
372390
// Write LogItem end time (V=2+)
373-
OUT.println("# " + item.getStopTime().toString());
391+
OUT.println(item.getStopTime()==null ? "#Incomplete" : "# " + item.getStopTime().toString());
374392
// Write LogItem runtime (V=3+)
375393
if(verbosity>=3) {
376-
OUT.println("# Runtime: " + (item.getStopTime().getTime() - item.getStartTime().getTime()));
394+
OUT.println(item.getStopTime()==null ? "# Runtime: -" : "# Runtime: " + (item.getStopTime().getTime() - item.getStartTime().getTime()));
377395
}
378396
}
379397
// TODO: Write Toggle Log info

0 commit comments

Comments
 (0)