Merge pull request #29 from bkuker/master
Move System.err log capture to GuiceStartup
This commit is contained in:
commit
583b1a78e6
@ -1,48 +0,0 @@
|
||||
package net.sf.openrocket.gui.figure3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
/**
|
||||
* Redirects system err into OpenRocket's log.debug() if openrocket.debug is enabled.
|
||||
* This lets me capture JOGL debug as log events, which can be included in error reports etc.
|
||||
* I wish I could get the JOGL debug log on a separate printstream, so I do not have to take
|
||||
* over all of ERR.
|
||||
*
|
||||
* @author bkuker
|
||||
*
|
||||
*/
|
||||
final class JoglDebugAdaptor {
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
|
||||
final static void plumbJoglDebug() {
|
||||
if (RocketFigure3d.is3dEnabled() && System.getProperty("openrocket.debug") != null) {
|
||||
System.setProperty("jogl.debug", "all");
|
||||
|
||||
System.setErr(new PrintStream(new OutputStream() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@Override
|
||||
public synchronized void write(int b) throws IOException {
|
||||
if (b == '\r' || b == '\n') {
|
||||
if (sb.toString().trim().length() > 0){
|
||||
String s = sb.toString();
|
||||
if ( Character.isWhitespace(s.charAt(0))){
|
||||
log.verbose(sb.toString());
|
||||
} else {
|
||||
log.debug(sb.toString());
|
||||
}
|
||||
}
|
||||
sb = new StringBuilder();
|
||||
} else {
|
||||
sb.append((char) b);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
@ -51,9 +51,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
|
||||
static {
|
||||
JoglDebugAdaptor.plumbJoglDebug();
|
||||
|
||||
static {
|
||||
//this allows the GL canvas and things like the motor selection
|
||||
//drop down to z-order themselves.
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.sf.openrocket.startup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Locale;
|
||||
import java.util.prefs.Preferences;
|
||||
@ -80,6 +82,7 @@ public class GuiceStartup {
|
||||
setPropertyIfNotSet("openrocket.debug.menu", "true");
|
||||
setPropertyIfNotSet("openrocket.debug.mutexlocation", "true");
|
||||
setPropertyIfNotSet("openrocket.debug.motordigest", "true");
|
||||
setPropertyIfNotSet("jogl.debug", "all");
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,6 +134,39 @@ public class GuiceStartup {
|
||||
str += " (" + LOG_STDOUT_PROPERTY + "=" + System.getProperty(LOG_STDOUT_PROPERTY) +
|
||||
" " + LOG_STDERR_PROPERTY + "=" + System.getProperty(LOG_STDERR_PROPERTY) + ")";
|
||||
log.info(str);
|
||||
|
||||
|
||||
|
||||
//Replace System.err with a PrintStream that logs lines to DEBUG, or VBOSE if they are indented.
|
||||
//If debug info is not being output to the console then the data is both logged and written to
|
||||
//stderr.
|
||||
final boolean writeToStderr = !( printer.getOutput(LogLevel.DEBUG) == System.out || printer.getOutput(LogLevel.DEBUG) == System.err);
|
||||
final PrintStream stdErr = System.err;
|
||||
System.setErr(new PrintStream(new OutputStream() {
|
||||
StringBuilder currentLine = new StringBuilder();
|
||||
@Override
|
||||
public synchronized void write(int b) throws IOException {
|
||||
if ( writeToStderr ){
|
||||
//Write to real stderr
|
||||
stdErr.write(b);
|
||||
}
|
||||
if (b == '\r' || b == '\n') {
|
||||
//Line is complete, log it
|
||||
if (currentLine.toString().trim().length() > 0){
|
||||
String s = currentLine.toString();
|
||||
if ( Character.isWhitespace(s.charAt(0))){
|
||||
log.verbose(currentLine.toString());
|
||||
} else {
|
||||
log.debug(currentLine.toString());
|
||||
}
|
||||
}
|
||||
currentLine = new StringBuilder();
|
||||
} else {
|
||||
//append to the line being built
|
||||
currentLine.append((char) b);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private static boolean setLogOutput(PrintStreamLogger logger, PrintStream stream, String level, LogLevel defaultLevel) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user