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() + "'.");
}
}