JAL-3384 -out can now be used without getdown launch. -out cannot use '../' in pathname
authorBen Soares <bsoares@dundee.ac.uk>
Thu, 1 Aug 2019 11:22:14 +0000 (12:22 +0100)
committerBen Soares <bsoares@dundee.ac.uk>
Thu, 1 Aug 2019 11:22:14 +0000 (12:22 +0100)
src/jalview/bin/Jalview.java

index b259741..0fc92f9 100755 (executable)
@@ -200,45 +200,46 @@ public class Jalview
     System.setSecurityManager(null);
 
     ArgsParser aparser = new ArgsParser(args);
+    String logFilename = aparser.getValue("out");
     // set stdout and stderr to file if launched by getdown
     String appdirString = System.getProperty("getdownappdir");
-    if (appdirString != null)
+    if (appdirString != null || logFilename != null)
     {
 
-      String logFilename = aparser.getValue("out");
-      String parent = appdirString;
-      if (logFilename == null)
+      if (logFilename == null
+              || logFilename.indexOf(".." + File.separator) > -1)
       {
         logFilename = "output.log";
       }
-      else
-      {
-        if (logFilename.startsWith(File.separator))
-        {
-          parent = null;
-        }
-      }
+
+      String parent = logFilename.startsWith(File.separator) ? null
+              : appdirString;
+
       File logFile = new File(parent, logFilename);
+
       if (logFile.exists())
       {
         logFile.delete();
       }
-      try
-      {
-        PrintStream logOut = new PrintStream(new FileOutputStream(logFile),
-                true);
-        System.setOut(logOut);
-        System.setErr(logOut);
 
-      } catch (IOException ioe)
-      {
-        System.err.println("Failed to open debug log [path="
-                + logFile.getAbsolutePath() + ", exception=" + ioe + "]");
-      }
-      // if we've redirected our log output, note where to
       if (logFile != null)
       {
-        System.out.println("Logging to '" + logFile + "'.");
+        System.out.println("About to start logging to '"
+                + logFile.getAbsolutePath() + "'.");
+        try
+        {
+          PrintStream logOut = new PrintStream(
+                  new FileOutputStream(logFile), true);
+          System.setOut(logOut);
+          System.setErr(logOut);
+
+        } catch (IOException ioe)
+        {
+          System.err.println("Failed to open log file [path="
+                  + logFile.getAbsolutePath() + ", exception=" + ioe + "]");
+        }
+        System.out.println(
+                "Now logging to '" + logFile.getAbsolutePath() + "'.");
       }
 
     }