Log to a file if running from a JAR

This commit is contained in:
Cameron Gutman
2014-01-01 15:33:48 -06:00
parent 101632c967
commit d99f0575f4
2 changed files with 18 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
package com.limelight;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
@@ -106,6 +110,15 @@ public class Limelight implements NvConnectionListener {
*/
//TODO: We should allow command line args to specify things like debug mode (verbose logging) or even start a stream directly.
public static void main(String args[]) {
// Redirect logging to a file if we're running from a JAR
if (LibraryHelper.isRunningFromJar()) {
try {
System.setErr(new PrintStream(new File("error.log")));
System.setOut(new PrintStream(new File("output.log")));
} catch (IOException e) {
}
}
//fix the menu bar if we are running in osx
if (System.getProperty("os.name").contains("Mac OS X")) {
// take the menu bar off the jframe

View File

@@ -94,4 +94,9 @@ public class LibraryHelper {
}
}
}
public static boolean isRunningFromJar() {
String classPath = LibraryHelper.class.getResource("LibraryHelper.class").toString();
return classPath.startsWith("jar:");
}
}