Use slf4j for all logging within the application.
This commit is contained in:
parent
487917b9c4
commit
96689c69e2
@ -31,8 +31,8 @@
|
||||
<classpathentry kind="lib" path="lib/jogl/jogl-all.jar" sourcepath="reference/jogl-v2.0-rc11-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib-test/test-plugin.jar"/>
|
||||
<classpathentry kind="lib" path="lib/annotation-detector-3.0.2-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="lib" path="lib/logback-classic-1.0.7.jar"/>
|
||||
<classpathentry kind="lib" path="lib/logback-core-1.0.7.jar"/>
|
||||
<classpathentry kind="lib" path="lib/slf4j-api-1.7.2.jar"/>
|
||||
<classpathentry kind="lib" path="lib/logback-classic-1.0.12.jar" sourcepath="reference/logback-classic-1.0.12-sources.jar"/>
|
||||
<classpathentry kind="lib" path="lib/logback-core-1.0.12.jar" sourcepath="lib/logback-core-1.0.7.jar"/>
|
||||
<classpathentry kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
BIN
core/lib/logback-classic-1.0.12.jar
Normal file
BIN
core/lib/logback-classic-1.0.12.jar
Normal file
Binary file not shown.
Binary file not shown.
BIN
core/lib/logback-core-1.0.12.jar
Normal file
BIN
core/lib/logback-core-1.0.12.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
core/reference/logback-classic-1.0.12-sources.jar
Normal file
BIN
core/reference/logback-classic-1.0.12-sources.jar
Normal file
Binary file not shown.
BIN
core/reference/logback-core-1.0.12-sources.jar
Normal file
BIN
core/reference/logback-core-1.0.12-sources.jar
Normal file
Binary file not shown.
@ -6,7 +6,13 @@
|
||||
<pattern><![CDATA[%-8relative %-5marker %-5level [%thread] %logger{2} - %message%n%caller{2, BAD}]]></pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="buffer" class="net.sf.openrocket.logging.LogbackBufferLoggerAdaptor">
|
||||
<encoder>
|
||||
<pattern><![CDATA[%-8relative %-5marker %-5level [%thread] %logger{2} - %message%n%caller{2, BAD}]]></pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="buffer" />
|
||||
</root>
|
||||
</configuration>
|
@ -23,15 +23,17 @@ import net.sf.openrocket.document.attachments.FileSystemAttachment;
|
||||
import net.sf.openrocket.gui.watcher.FileWatcher;
|
||||
import net.sf.openrocket.gui.watcher.WatchEvent;
|
||||
import net.sf.openrocket.gui.watcher.WatchService;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
import net.sf.openrocket.util.ChangeSource;
|
||||
import net.sf.openrocket.util.FileUtils;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DecalRegistry {
|
||||
private static LogHelper log = Application.getLogger();
|
||||
private static Logger log = LoggerFactory.getLogger(DecalRegistry.class);
|
||||
|
||||
private WatchService watchService = Application.getWatchService();
|
||||
|
||||
|
@ -16,7 +16,6 @@ import net.sf.openrocket.document.events.DocumentChangeEvent;
|
||||
import net.sf.openrocket.document.events.DocumentChangeListener;
|
||||
import net.sf.openrocket.document.events.SimulationChangeEvent;
|
||||
import net.sf.openrocket.logging.Markers;
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
||||
@ -557,7 +556,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
log.error(error + ": this=" + this + " undoPosition=" + undoPosition +
|
||||
" undoHistory.size=" + undoHistory.size() + " isClean=" + isCleanState() +
|
||||
" nextDescription=" + nextDescription + " storedDescription=" + storedDescription,
|
||||
new TraceException());
|
||||
new Throwable());
|
||||
|
||||
if (!undoErrorReported) {
|
||||
undoErrorReported = true;
|
||||
|
@ -7,22 +7,23 @@ import net.sf.openrocket.file.DocumentLoadingContext;
|
||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||
import net.sf.openrocket.file.simplesax.PlainTextHandler;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.simulation.FlightDataBranch;
|
||||
import net.sf.openrocket.simulation.FlightDataType;
|
||||
import net.sf.openrocket.simulation.FlightEvent;
|
||||
import net.sf.openrocket.simulation.FlightEvent.Type;
|
||||
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.unit.UnitGroup;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class FlightDataBranchHandler extends AbstractElementHandler {
|
||||
@SuppressWarnings("unused")
|
||||
private final DocumentLoadingContext context;
|
||||
private final FlightDataType[] types;
|
||||
private final FlightDataBranch branch;
|
||||
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
private static final Logger log = LoggerFactory.getLogger(FlightDataBranchHandler.class);
|
||||
private final SingleSimulationHandler simHandler;
|
||||
|
||||
public FlightDataBranchHandler(String name, String typeList, SingleSimulationHandler simHandler, DocumentLoadingContext context) {
|
||||
|
@ -26,8 +26,6 @@ import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import com.jogamp.opengl.JoglVersion;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.communication.BugReporter;
|
||||
import net.sf.openrocket.gui.components.SelectableLabel;
|
||||
@ -36,11 +34,14 @@ import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.LogLevelBufferLogger;
|
||||
import net.sf.openrocket.logging.LogLine;
|
||||
import net.sf.openrocket.logging.LoggingSystemSetup;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
import net.sf.openrocket.util.BuildProperties;
|
||||
import net.sf.openrocket.util.JarUtil;
|
||||
|
||||
import com.jogamp.opengl.JoglVersion;
|
||||
|
||||
public class BugReportDialog extends JDialog {
|
||||
|
||||
private static final String REPORT_EMAIL = "openrocket-bugs@lists.sourceforge.net";
|
||||
@ -73,16 +74,16 @@ public class BugReportDialog extends JDialog {
|
||||
"gapleft para, split 2, gapright rel");
|
||||
panel.add(new SelectableLabel(REPORT_EMAIL), "growx, wrap para");
|
||||
|
||||
|
||||
|
||||
final JTextArea textArea = new JTextArea(message, 20, 70);
|
||||
textArea.setEditable(true);
|
||||
panel.add(new JScrollPane(textArea), "grow, wrap");
|
||||
|
||||
|
||||
|
||||
panel.add(new StyledLabel(trans.get("bugreport.lbl.Theinformation"), -1), "wrap para");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////Close button
|
||||
JButton close = new JButton(trans.get("dlg.but.close"));
|
||||
close.addActionListener(new ActionListener() {
|
||||
@ -93,7 +94,7 @@ public class BugReportDialog extends JDialog {
|
||||
});
|
||||
panel.add(close, "right, sizegroup buttons, split");
|
||||
|
||||
|
||||
|
||||
//// Mail button
|
||||
// if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.MAIL)) {
|
||||
// JButton mail = new JButton("Open email");
|
||||
@ -108,7 +109,7 @@ public class BugReportDialog extends JDialog {
|
||||
// panel.add(mail, "right, sizegroup buttons");
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//// Send bug report button
|
||||
JButton send = new JButton(trans.get("bugreport.dlg.but.Sendbugreport"));
|
||||
//// Automatically send the bug report to the OpenRocket developers.
|
||||
@ -147,7 +148,7 @@ public class BugReportDialog extends JDialog {
|
||||
ex.getClass().getSimpleName() + ": " + ex.getMessage(), " ",
|
||||
//// Please send the report manually to
|
||||
trans.get("bugreport.dlg.failedmsg2") + " " + REPORT_EMAIL },
|
||||
//// Error sending report
|
||||
//// Error sending report
|
||||
trans.get("bugreport.dlg.failedmsg3"), JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
@ -165,7 +166,7 @@ public class BugReportDialog extends JDialog {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show a general bug report dialog allowing the user to input information about
|
||||
* the bug they encountered.
|
||||
@ -197,7 +198,7 @@ public class BugReportDialog extends JDialog {
|
||||
sb.append('\n');
|
||||
sb.append('\n');
|
||||
|
||||
|
||||
|
||||
sb.append("(Do not modify anything below this line.)\n");
|
||||
sb.append("---------- System information ----------\n");
|
||||
addSystemInformation(sb);
|
||||
@ -207,7 +208,7 @@ public class BugReportDialog extends JDialog {
|
||||
sb.append('\n');
|
||||
|
||||
BugReportDialog reportDialog = new BugReportDialog(parent,
|
||||
trans.get("bugreport.reportDialog.txt"), sb.toString(), false);
|
||||
trans.get("bugreport.reportDialog.txt"), sb.toString(), false);
|
||||
reportDialog.setVisible(true);
|
||||
}
|
||||
|
||||
@ -231,7 +232,7 @@ public class BugReportDialog extends JDialog {
|
||||
sb.append('\n');
|
||||
sb.append('\n');
|
||||
|
||||
|
||||
|
||||
sb.append("Include your email address (optional; it helps if we can " +
|
||||
"contact you in case we need additional information):\n");
|
||||
sb.append('\n');
|
||||
@ -247,7 +248,7 @@ public class BugReportDialog extends JDialog {
|
||||
sb.append(sw.getBuffer());
|
||||
sb.append('\n');
|
||||
|
||||
|
||||
|
||||
sb.append("---------- Thread information ----------\n");
|
||||
if (t == null) {
|
||||
sb.append("Thread is not specified.");
|
||||
@ -256,7 +257,7 @@ public class BugReportDialog extends JDialog {
|
||||
}
|
||||
sb.append('\n');
|
||||
|
||||
|
||||
|
||||
sb.append("---------- System information ----------\n");
|
||||
addSystemInformation(sb);
|
||||
sb.append("---------- Error log ----------\n");
|
||||
@ -301,7 +302,7 @@ public class BugReportDialog extends JDialog {
|
||||
|
||||
|
||||
private static void addErrorLog(StringBuilder sb) {
|
||||
LogLevelBufferLogger buffer = Application.getLogBuffer();
|
||||
LogLevelBufferLogger buffer = LoggingSystemSetup.getBufferLogger();
|
||||
List<LogLine> logs = buffer.getLogs();
|
||||
for (LogLine l : logs) {
|
||||
sb.append(l.toString()).append('\n');
|
||||
@ -309,7 +310,7 @@ public class BugReportDialog extends JDialog {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Open the default email client with the suitable bug report.
|
||||
* Note that this does not work on some systems even if Desktop.isSupported()
|
||||
@ -329,8 +330,8 @@ public class BugReportDialog extends JDialog {
|
||||
throw new BugException(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
String mailto = "mailto:" + REPORT_EMAIL
|
||||
+ "?subject=Bug%20report%20for%20OpenRocket%20" + version
|
||||
+ "?body=" + text;
|
||||
|
@ -38,9 +38,6 @@ import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.table.TableRowSorter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.gui.adaptors.Column;
|
||||
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
|
||||
@ -52,19 +49,22 @@ import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.logging.LogLevel;
|
||||
import net.sf.openrocket.logging.LogLevelBufferLogger;
|
||||
import net.sf.openrocket.logging.LogLine;
|
||||
import net.sf.openrocket.logging.LoggingSystemSetup;
|
||||
import net.sf.openrocket.logging.Markers;
|
||||
import net.sf.openrocket.logging.StackTraceWriter;
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.NumericComparator;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DebugLogDialog extends JDialog {
|
||||
private static final Logger log = LoggerFactory.getLogger(DebugLogDialog.class);
|
||||
|
||||
private static final int POLL_TIME = 250;
|
||||
private static final String STACK_TRACE_MARK = "\uFF01";
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
|
||||
private static final EnumMap<LogLevel, Color> backgroundColors = new EnumMap<LogLevel, Color>(LogLevel.class);
|
||||
static {
|
||||
for (LogLevel l : LogLevel.values()) {
|
||||
@ -94,7 +94,7 @@ public class DebugLogDialog extends JDialog {
|
||||
private final JCheckBox followBox;
|
||||
private final Timer timer;
|
||||
|
||||
|
||||
|
||||
private final JTable table;
|
||||
private final ColumnTableModel model;
|
||||
private final TableRowSorter<TableModel> sorter;
|
||||
@ -110,8 +110,7 @@ public class DebugLogDialog extends JDialog {
|
||||
//// OpenRocket debug log
|
||||
super(parent, trans.get("debuglogdlg.OpenRocketdebuglog"));
|
||||
|
||||
// Start listening to log lines
|
||||
LogHelper applicationLog = Application.getLogger();
|
||||
LogHelper applicationLog = LoggingSystemSetup.getInstance();
|
||||
if (applicationLog instanceof DelegatorLogger) {
|
||||
log.info("Adding log listener");
|
||||
delegator = (DelegatorLogger) applicationLog;
|
||||
@ -124,19 +123,19 @@ public class DebugLogDialog extends JDialog {
|
||||
}
|
||||
|
||||
// Fetch old log lines
|
||||
LogLevelBufferLogger bufferLogger = Application.getLogBuffer();
|
||||
LogLevelBufferLogger bufferLogger = LoggingSystemSetup.getBufferLogger();
|
||||
if (bufferLogger != null) {
|
||||
buffer.addAll(bufferLogger.getLogs());
|
||||
} else {
|
||||
log.warn("Application does not have a log buffer");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create the UI
|
||||
JPanel mainPanel = new JPanel(new MigLayout("fill"));
|
||||
this.add(mainPanel);
|
||||
|
||||
|
||||
|
||||
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
||||
split.setDividerLocation(0.7);
|
||||
mainPanel.add(split, "grow");
|
||||
@ -179,22 +178,22 @@ public class DebugLogDialog extends JDialog {
|
||||
});
|
||||
panel.add(clear, "right, wrap");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Create the table model
|
||||
model = new ColumnTableModel(
|
||||
|
||||
new Column("#") {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
return buffer.get(row).getLogCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 60;
|
||||
}
|
||||
},
|
||||
|
||||
new Column("#") {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
return buffer.get(row).getLogCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 60;
|
||||
}
|
||||
},
|
||||
//// Time
|
||||
new Column(trans.get("debuglogdlg.col.Time")) {
|
||||
@Override
|
||||
@ -238,12 +237,8 @@ public class DebugLogDialog extends JDialog {
|
||||
new Column(trans.get("debuglogdlg.col.Location")) {
|
||||
@Override
|
||||
public Object getValueAt(int row) {
|
||||
TraceException e = buffer.get(row).getTrace();
|
||||
if (e != null) {
|
||||
return e.getMessage();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
String e = buffer.get(row).getLocation();
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -263,13 +258,13 @@ public class DebugLogDialog extends JDialog {
|
||||
return 580;
|
||||
}
|
||||
}
|
||||
|
||||
) {
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return buffer.size();
|
||||
}
|
||||
};
|
||||
|
||||
) {
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return buffer.size();
|
||||
}
|
||||
};
|
||||
|
||||
table = new JTable(model);
|
||||
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
@ -296,12 +291,12 @@ public class DebugLogDialog extends JDialog {
|
||||
table.setRowSorter(sorter);
|
||||
sorter.setRowFilter(new LogFilter());
|
||||
|
||||
|
||||
|
||||
panel.add(new JScrollPane(table), "span, grow, width " +
|
||||
(Toolkit.getDefaultToolkit().getScreenSize().width * 8 / 10) +
|
||||
"px, height 400px");
|
||||
|
||||
|
||||
|
||||
panel = new JPanel(new MigLayout("fill"));
|
||||
split.add(panel);
|
||||
|
||||
@ -337,7 +332,7 @@ public class DebugLogDialog extends JDialog {
|
||||
GUIUtil.changeFontSize(stackTraceLabel, -2);
|
||||
panel.add(new JScrollPane(stackTraceLabel), "grow");
|
||||
|
||||
|
||||
|
||||
//Close button
|
||||
JButton close = new JButton(trans.get("dlg.but.close"));
|
||||
close.addActionListener(new ActionListener() {
|
||||
@ -348,7 +343,7 @@ public class DebugLogDialog extends JDialog {
|
||||
});
|
||||
mainPanel.add(close, "newline para, right, tag ok");
|
||||
|
||||
|
||||
|
||||
// Use timer to purge the queue so as not to overwhelm the EDT with events
|
||||
timer = new Timer(POLL_TIME, new ActionListener() {
|
||||
@Override
|
||||
@ -375,8 +370,6 @@ public class DebugLogDialog extends JDialog {
|
||||
followBox.requestFocus();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateSelected(int row) {
|
||||
if (row < 0) {
|
||||
|
||||
@ -393,12 +386,8 @@ public class DebugLogDialog extends JDialog {
|
||||
numberLabel.setText("" + line.getLogCount());
|
||||
timeLabel.setText(String.format("%.3f s", line.getTimestamp() / 1000.0));
|
||||
levelLabel.setText(line.getLevel().toString());
|
||||
TraceException e = line.getTrace();
|
||||
if (e != null) {
|
||||
locationLabel.setText(e.getMessage());
|
||||
} else {
|
||||
locationLabel.setText("-");
|
||||
}
|
||||
String e = line.getLocation();
|
||||
locationLabel.setText(e);
|
||||
messageLabel.setText(line.getMessage());
|
||||
Throwable t = line.getCause();
|
||||
if (t != null) {
|
||||
@ -502,7 +491,7 @@ public class DebugLogDialog extends JDialog {
|
||||
this.setBackground(bg);
|
||||
|
||||
this.setOpaque(true);
|
||||
this.setText(value.toString());
|
||||
this.setText(String.valueOf(value));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -15,19 +15,20 @@ import javax.media.opengl.fixedfunc.GLLightingFunc;
|
||||
import net.sf.openrocket.gui.figure3d.geometry.ComponentRenderer;
|
||||
import net.sf.openrocket.gui.figure3d.geometry.DisplayListComponentRenderer;
|
||||
import net.sf.openrocket.gui.figure3d.geometry.Geometry.Surface;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/*
|
||||
* @author Bill Kuker <bkuker@billkuker.com>
|
||||
*/
|
||||
public abstract class RocketRenderer {
|
||||
protected static final LogHelper log = Application.getLogger();
|
||||
protected static final Logger log = LoggerFactory.getLogger(RocketRenderer.class);
|
||||
|
||||
final ComponentRenderer cr = new DisplayListComponentRenderer();
|
||||
|
||||
|
@ -8,7 +8,6 @@ import javax.media.opengl.glu.GLU;
|
||||
import javax.media.opengl.glu.GLUquadric;
|
||||
|
||||
import net.sf.openrocket.gui.figure3d.geometry.Geometry.Surface;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.rocketcomponent.BodyTube;
|
||||
import net.sf.openrocket.rocketcomponent.FinSet;
|
||||
@ -18,15 +17,17 @@ import net.sf.openrocket.rocketcomponent.RingComponent;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.rocketcomponent.Transition;
|
||||
import net.sf.openrocket.rocketcomponent.Transition.Shape;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.Coordinate;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/*
|
||||
* @author Bill Kuker <bkuker@billkuker.com>
|
||||
*/
|
||||
public class ComponentRenderer {
|
||||
@SuppressWarnings("unused")
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
private static final Logger log = LoggerFactory.getLogger(ComponentRenderer.class);
|
||||
|
||||
private int LOD = 80;
|
||||
|
||||
|
@ -3,15 +3,14 @@ package net.sf.openrocket.gui.main;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.openrocket.gui.dialogs.BugReportDialog;
|
||||
import net.sf.openrocket.logging.Markers;
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.startup.ExceptionHandler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, ExceptionHandler {
|
||||
|
||||
@ -29,8 +28,8 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
private volatile boolean handling = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void uncaughtException(final Thread thread, final Throwable throwable) {
|
||||
|
||||
@ -100,7 +99,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
*/
|
||||
@Override
|
||||
public void handleErrorCondition(String message) {
|
||||
log.error(message, new TraceException());
|
||||
log.error(message, new Throwable());
|
||||
handleErrorCondition(new InternalException(message));
|
||||
}
|
||||
|
||||
@ -197,7 +196,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Normal exception, show question dialog
|
||||
log.info("Showing Exception dialog");
|
||||
int selection = JOptionPane.showOptionDialog(null, new Object[] {
|
||||
@ -207,7 +206,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
" ",
|
||||
"Please take a moment to report this bug to the developers.",
|
||||
"This can be done automatically if you have an Internet connection."
|
||||
}, "Uncaught exception", JOptionPane.DEFAULT_OPTION,
|
||||
}, "Uncaught exception", JOptionPane.DEFAULT_OPTION,
|
||||
JOptionPane.ERROR_MESSAGE, null,
|
||||
new Object[] { "View bug report", "Close" }, "View bug report");
|
||||
|
||||
@ -223,7 +222,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Registers the uncaught exception handler. This should be used to ensure that
|
||||
* all necessary registrations are performed.
|
||||
@ -231,11 +230,11 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
public void registerExceptionHandler() {
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
|
||||
|
||||
// Handler for modal dialogs of Sun's Java implementation
|
||||
// See bug ID 4499199.
|
||||
System.setProperty("sun.awt.exception.handler", AwtHandler.class.getName());
|
||||
|
||||
|
||||
reserveMemory();
|
||||
|
||||
}
|
||||
@ -252,7 +251,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return whether this throwable was caused by an OutOfMemoryError
|
||||
* condition. An exception is deemed to be caused by OutOfMemoryError
|
||||
@ -274,13 +273,13 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handler used in modal dialogs by Sun Java implementation.
|
||||
*/
|
||||
public static class AwtHandler {
|
||||
public void handle(Throwable t) {
|
||||
Application.getExceptionHandler().uncaughtException(Thread.currentThread(), t);
|
||||
Application.getExceptionHandler().uncaughtException(Thread.currentThread(), t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +294,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
|
||||
// NOTE: Calling method logs the entire throwable, so log only message here
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Detect and ignore bug 6826104 in Sun JRE.
|
||||
*/
|
||||
@ -305,10 +304,10 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
if (trace.length > 3 &&
|
||||
trace[0].getClassName().equals("sun.awt.X11.XWindowPeer") &&
|
||||
trace[0].getMethodName().equals("restoreTransientFor") &&
|
||||
|
||||
|
||||
trace[1].getClassName().equals("sun.awt.X11.XWindowPeer") &&
|
||||
trace[1].getMethodName().equals("removeFromTransientFors") &&
|
||||
|
||||
|
||||
trace[2].getClassName().equals("sun.awt.X11.XWindowPeer") &&
|
||||
trace[2].getMethodName().equals("setModalBlocked")) {
|
||||
log.warn("Ignoring Sun JRE bug (6826104): http://bugs.sun.com/view_bug.do?bug_id=6826104" + t);
|
||||
@ -317,7 +316,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Detect and ignore bug 6828938 in Sun JRE 1.6.0_14 - 1.6.0_16.
|
||||
*/
|
||||
@ -327,7 +326,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
if (elements.length >= 3 &&
|
||||
(buggyClass.equals(elements[0].getClassName()) ||
|
||||
buggyClass.equals(elements[1].getClassName()) ||
|
||||
buggyClass.equals(elements[2].getClassName()))) {
|
||||
buggyClass.equals(elements[2].getClassName()))) {
|
||||
log.warn("Ignoring Sun JRE bug 6828938: " +
|
||||
"(see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6828938): " + t);
|
||||
return true;
|
||||
@ -343,10 +342,10 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
if (trace.length > 3 &&
|
||||
trace[0].getClassName().equals("javax.swing.JComponent") &&
|
||||
trace[0].getMethodName().equals("repaint") &&
|
||||
|
||||
|
||||
trace[1].getClassName().equals("sun.swing.FilePane$2") &&
|
||||
trace[1].getMethodName().equals("repaintListSelection") &&
|
||||
|
||||
|
||||
trace[2].getClassName().equals("sun.swing.FilePane$2") &&
|
||||
trace[2].getMethodName().equals("repaintSelection")) {
|
||||
log.warn("Ignoring Sun JRE bug 6561072 " +
|
||||
@ -355,7 +354,7 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Detect and ignore bug 6933331 in Sun JRE 1.6.0_18 and others
|
||||
*/
|
||||
@ -380,10 +379,10 @@ public class SwingExceptionHandler implements Thread.UncaughtExceptionHandler, E
|
||||
if (trace.length > 3 &&
|
||||
trace[0].getClassName().equals("sun.awt.shell.Win32ShellFolder2") &&
|
||||
trace[0].getMethodName().equals("pidlsEqual") &&
|
||||
|
||||
|
||||
trace[1].getClassName().equals("sun.awt.shell.Win32ShellFolder2") &&
|
||||
trace[1].getMethodName().equals("equals") &&
|
||||
|
||||
|
||||
trace[2].getClassName().equals("sun.awt.shell.Win32ShellFolderManager2") &&
|
||||
trace[2].getMethodName().equals("isFileSystemRoot")) {
|
||||
log.warn("Ignoring Sun JRE bug " +
|
||||
|
@ -1,137 +1,139 @@
|
||||
package net.sf.openrocket.gui.print.visitor;
|
||||
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Rectangle;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
import net.sf.openrocket.gui.print.AbstractPrintable;
|
||||
import net.sf.openrocket.gui.print.ITextHelper;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.openrocket.gui.print.AbstractPrintable;
|
||||
import net.sf.openrocket.gui.print.ITextHelper;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Rectangle;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
|
||||
/**
|
||||
* Common logic for printing strategies.
|
||||
*/
|
||||
public abstract class AbstractPrintStrategy<V> {
|
||||
/**
|
||||
* The logger.
|
||||
*/
|
||||
protected static final LogHelper log = Application.getLogger();
|
||||
/**
|
||||
* The iText document.
|
||||
*/
|
||||
protected Document document;
|
||||
/**
|
||||
* The direct iText writer.
|
||||
*/
|
||||
protected PdfWriter writer;
|
||||
/**
|
||||
* The stages selected.
|
||||
*/
|
||||
protected Set<Integer> stages;
|
||||
/**
|
||||
* Strategy for fitting multiple components onto a page.
|
||||
*/
|
||||
protected PageFitPrintStrategy pageFitPrint;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param doc the document
|
||||
* @param pageFit the page fitting strategy
|
||||
* @param theWriter the pdf writer
|
||||
* @param theStages the set of stages in the rocket
|
||||
*/
|
||||
public AbstractPrintStrategy(Document doc, PageFitPrintStrategy pageFit, PdfWriter theWriter,
|
||||
Set<Integer> theStages) {
|
||||
document = doc;
|
||||
pageFitPrint = pageFit;
|
||||
writer = theWriter;
|
||||
stages = theStages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurse through the given rocket component.
|
||||
*
|
||||
* @param root the root component; all children will be printed recursively
|
||||
*/
|
||||
public V writeToDocument(final RocketComponent root) {
|
||||
return goDeep(root.getChildren());
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurse through the given rocket component.
|
||||
*
|
||||
* @param theRc an array of rocket components; all children will be printed recursively
|
||||
*/
|
||||
protected abstract V goDeep(List<RocketComponent> theRc);
|
||||
|
||||
/**
|
||||
* Determine if the image will fit on the given page.
|
||||
*
|
||||
* @param pageSize the page size
|
||||
* @param wImage the width of the thing to be printed
|
||||
* @param hImage the height of the thing to be printed
|
||||
*
|
||||
* @return true if the thing to be printed will fit on a single page
|
||||
*/
|
||||
protected boolean fitsOnOnePage(Dimension pageSize, double wImage, double hImage) {
|
||||
double wPage = pageSize.getWidth() - PageFitPrintStrategy.MARGIN * 2;
|
||||
double hPage = pageSize.getHeight() - PageFitPrintStrategy.MARGIN * 2;
|
||||
|
||||
int wRatio = (int) Math.ceil(wImage / wPage);
|
||||
int hRatio = (int) Math.ceil(hImage / hPage);
|
||||
|
||||
return wRatio <= 1.0d && hRatio <= 1.0d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dimensions of the paper page.
|
||||
*
|
||||
* @return an internal Dimension
|
||||
*/
|
||||
protected Dimension getPageSize() {
|
||||
return new Dimension(document.getPageSize().getWidth(),
|
||||
document.getPageSize().getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the strategy's set of stage numbers (to print) contains the specified stage.
|
||||
*
|
||||
* @param stageNumber a stage number
|
||||
*
|
||||
* @return true if the strategy contains the stage number provided
|
||||
*/
|
||||
public boolean shouldPrintStage(int stageNumber) {
|
||||
if (stages == null || stages.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (final Integer stage : stages) {
|
||||
if (stage == stageNumber) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void render(final AbstractPrintable thePrintable) throws DocumentException {
|
||||
java.awt.Dimension size = thePrintable.getSize();
|
||||
final Dimension pageSize = getPageSize();
|
||||
if (fitsOnOnePage(pageSize, size.getWidth(), size.getHeight())) {
|
||||
pageFitPrint.addComponent(thePrintable);
|
||||
}
|
||||
else {
|
||||
BufferedImage image = (BufferedImage) thePrintable.createImage();
|
||||
ITextHelper.renderImageAcrossPages(new Rectangle(pageSize.getWidth(), pageSize.getHeight()),
|
||||
document, writer, image);
|
||||
document.newPage();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The logger.
|
||||
*/
|
||||
protected static final Logger log = LoggerFactory.getLogger(AbstractPrintStrategy.class);
|
||||
/**
|
||||
* The iText document.
|
||||
*/
|
||||
protected Document document;
|
||||
/**
|
||||
* The direct iText writer.
|
||||
*/
|
||||
protected PdfWriter writer;
|
||||
/**
|
||||
* The stages selected.
|
||||
*/
|
||||
protected Set<Integer> stages;
|
||||
/**
|
||||
* Strategy for fitting multiple components onto a page.
|
||||
*/
|
||||
protected PageFitPrintStrategy pageFitPrint;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param doc the document
|
||||
* @param pageFit the page fitting strategy
|
||||
* @param theWriter the pdf writer
|
||||
* @param theStages the set of stages in the rocket
|
||||
*/
|
||||
public AbstractPrintStrategy(Document doc, PageFitPrintStrategy pageFit, PdfWriter theWriter,
|
||||
Set<Integer> theStages) {
|
||||
document = doc;
|
||||
pageFitPrint = pageFit;
|
||||
writer = theWriter;
|
||||
stages = theStages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurse through the given rocket component.
|
||||
*
|
||||
* @param root the root component; all children will be printed recursively
|
||||
*/
|
||||
public V writeToDocument(final RocketComponent root) {
|
||||
return goDeep(root.getChildren());
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurse through the given rocket component.
|
||||
*
|
||||
* @param theRc an array of rocket components; all children will be printed recursively
|
||||
*/
|
||||
protected abstract V goDeep(List<RocketComponent> theRc);
|
||||
|
||||
/**
|
||||
* Determine if the image will fit on the given page.
|
||||
*
|
||||
* @param pageSize the page size
|
||||
* @param wImage the width of the thing to be printed
|
||||
* @param hImage the height of the thing to be printed
|
||||
*
|
||||
* @return true if the thing to be printed will fit on a single page
|
||||
*/
|
||||
protected boolean fitsOnOnePage(Dimension pageSize, double wImage, double hImage) {
|
||||
double wPage = pageSize.getWidth() - PageFitPrintStrategy.MARGIN * 2;
|
||||
double hPage = pageSize.getHeight() - PageFitPrintStrategy.MARGIN * 2;
|
||||
|
||||
int wRatio = (int) Math.ceil(wImage / wPage);
|
||||
int hRatio = (int) Math.ceil(hImage / hPage);
|
||||
|
||||
return wRatio <= 1.0d && hRatio <= 1.0d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dimensions of the paper page.
|
||||
*
|
||||
* @return an internal Dimension
|
||||
*/
|
||||
protected Dimension getPageSize() {
|
||||
return new Dimension(document.getPageSize().getWidth(),
|
||||
document.getPageSize().getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the strategy's set of stage numbers (to print) contains the specified stage.
|
||||
*
|
||||
* @param stageNumber a stage number
|
||||
*
|
||||
* @return true if the strategy contains the stage number provided
|
||||
*/
|
||||
public boolean shouldPrintStage(int stageNumber) {
|
||||
if (stages == null || stages.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (final Integer stage : stages) {
|
||||
if (stage == stageNumber) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void render(final AbstractPrintable thePrintable) throws DocumentException {
|
||||
java.awt.Dimension size = thePrintable.getSize();
|
||||
final Dimension pageSize = getPageSize();
|
||||
if (fitsOnOnePage(pageSize, size.getWidth(), size.getHeight())) {
|
||||
pageFitPrint.addComponent(thePrintable);
|
||||
}
|
||||
else {
|
||||
BufferedImage image = (BufferedImage) thePrintable.createImage();
|
||||
ITextHelper.renderImageAcrossPages(new Rectangle(pageSize.getWidth(), pageSize.getHeight()),
|
||||
document, writer, image);
|
||||
document.newPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,20 +3,22 @@
|
||||
*/
|
||||
package net.sf.openrocket.gui.print.visitor;
|
||||
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.pdf.PdfContentByte;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
import net.sf.openrocket.gui.print.PrintUnit;
|
||||
import net.sf.openrocket.gui.print.PrintableComponent;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.openrocket.gui.print.PrintUnit;
|
||||
import net.sf.openrocket.gui.print.PrintableComponent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.pdf.PdfContentByte;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
|
||||
/**
|
||||
* A strategy for drawing multiple rocket components onto as few pages as possible.
|
||||
*
|
||||
@ -30,7 +32,7 @@ public class PageFitPrintStrategy {
|
||||
/**
|
||||
* The logger.
|
||||
*/
|
||||
private static final LogHelper log = Application.getLogger();
|
||||
private static final Logger log = LoggerFactory.getLogger(PageFitPrintStrategy.class);
|
||||
|
||||
/**
|
||||
* The iText document.
|
||||
|
@ -14,9 +14,11 @@ import net.miginfocom.swing.MigLayout;
|
||||
import net.sf.openrocket.database.motor.ThrustCurveMotorSetDatabase;
|
||||
import net.sf.openrocket.gui.main.Splash;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.startup.MotorDatabaseLoader;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
@ -29,8 +31,9 @@ import com.google.inject.Provider;
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
*/
|
||||
public class BlockingMotorDatabaseProvider implements Provider<ThrustCurveMotorSetDatabase> {
|
||||
@Inject
|
||||
private LogHelper log;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BlockingMotorDatabaseProvider.class);
|
||||
|
||||
@Inject
|
||||
private Translator trans;
|
||||
|
||||
@ -58,7 +61,7 @@ public class BlockingMotorDatabaseProvider implements Provider<ThrustCurveMotorS
|
||||
SplashScreen splash = Splash.getSplashScreen();
|
||||
if (splash == null || !splash.isVisible()) {
|
||||
|
||||
log.info(1, "Motor database not loaded yet, displaying dialog");
|
||||
log.info("Motor database not loaded yet, displaying dialog");
|
||||
|
||||
final LoadingDialog dialog = new LoadingDialog();
|
||||
|
||||
@ -84,7 +87,7 @@ public class BlockingMotorDatabaseProvider implements Provider<ThrustCurveMotorS
|
||||
|
||||
} else {
|
||||
|
||||
log.info(1, "Motor database not loaded yet, splash screen still present, delaying until loaded");
|
||||
log.info("Motor database not loaded yet, splash screen still present, delaying until loaded");
|
||||
loader.blockUntilLoaded();
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package net.sf.openrocket.l10n;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
|
||||
/**
|
||||
@ -83,7 +82,7 @@ public class ClassBasedTranslator implements Translator {
|
||||
|
||||
|
||||
private String findClassName() {
|
||||
TraceException trace = new TraceException();
|
||||
Throwable trace = new Throwable();
|
||||
StackTraceElement stack[] = trace.getStackTrace();
|
||||
final int index = 2 + levels;
|
||||
if (stack.length <= index) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.sf.openrocket.logging;
|
||||
|
||||
import net.sf.openrocket.util.BugException;
|
||||
|
||||
|
||||
/**
|
||||
@ -23,27 +22,7 @@ import net.sf.openrocket.util.BugException;
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
*/
|
||||
public abstract class LogHelper {
|
||||
/**
|
||||
* Level from which upward a TraceException is added to the log lines.
|
||||
*/
|
||||
private static final LogLevel TRACING_LOG_LEVEL =
|
||||
LogLevel.fromString(System.getProperty("openrocket.log.tracelevel"), LogLevel.INFO);
|
||||
|
||||
private static final DelegatorLogger delegator = new DelegatorLogger();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the logger to be used in logging.
|
||||
*
|
||||
* @return the logger to be used in all logging.
|
||||
*/
|
||||
public static LogHelper getInstance() {
|
||||
return delegator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Log a LogLine object. This method needs to be able to cope with multiple threads
|
||||
* accessing it concurrently (for example by being synchronized).
|
||||
@ -52,466 +31,4 @@ public abstract class LogHelper {
|
||||
*/
|
||||
public abstract void log(LogLine line);
|
||||
|
||||
|
||||
/**
|
||||
* Log using VBOSE level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void verbose(String message) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.VBOSE, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using VBOSE level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void verbose(String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.VBOSE, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using VBOSE level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void verbose(int levels, String message) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.VBOSE, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using VBOSE level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void verbose(int levels, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.VBOSE, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log using DEBUG level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void debug(String message) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.DEBUG, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using DEBUG level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void debug(String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.DEBUG, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using DEBUG level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void debug(int levels, String message) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.DEBUG, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using DEBUG level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void debug(int levels, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.DEBUG, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log using INFO level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void info(String message) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.INFO, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using INFO level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void info(String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.INFO, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using INFO level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void info(int levels, String message) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.INFO, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using INFO level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void info(int levels, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.INFO, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log using USER level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void user(String message) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.USER, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using USER level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void user(String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.USER, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using USER level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void user(int levels, String message) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.USER, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using USER level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void user(int levels, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.USER, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log using WARN level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void warn(String message) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.WARN, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using WARN level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void warn(String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.WARN, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using WARN level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void warn(int levels, String message) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.WARN, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using WARN level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void warn(int levels, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.WARN, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Log using ERROR level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void error(String message) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.ERROR, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using ERROR level.
|
||||
*
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void error(String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(0, LogLevel.ERROR, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using ERROR level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void error(int levels, String message) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.ERROR, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using ERROR level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void error(int levels, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(levels, LogLevel.ERROR, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Log using the provided log level.
|
||||
*
|
||||
* @param level the logging level.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void log(LogLevel level, String message) {
|
||||
try {
|
||||
log(createLogLine(0, level, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using the provided log level.
|
||||
*
|
||||
* @param level the logging level.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void log(LogLevel level, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(0, level, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using the provided log level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param level the logging level.
|
||||
* @param message the logged message (may be null).
|
||||
*/
|
||||
public void log(int levels, LogLevel level, String message) {
|
||||
try {
|
||||
log(createLogLine(levels, level, message, null));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log using the provided log level.
|
||||
*
|
||||
* @param levels number of additional levels of stack trace to include.
|
||||
* @param level the logging level.
|
||||
* @param message the logged message (may be null).
|
||||
* @param cause the causing exception (may be null).
|
||||
*/
|
||||
public void log(int levels, LogLevel level, String message, Throwable cause) {
|
||||
try {
|
||||
log(createLogLine(levels, level, message, cause));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates, logs and throws a BugException. The message is logged at
|
||||
* ERROR level.
|
||||
* <p>
|
||||
* This method never returns normally.
|
||||
*
|
||||
* @param message the message for the log and exception.
|
||||
* @throws BugException always.
|
||||
*/
|
||||
public void throwBugException(String message) throws BugException {
|
||||
BugException e = new BugException(message);
|
||||
log(createLogLine(0, LogLevel.ERROR, message, e));
|
||||
throw e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates, logs and throws a BugException. The message is logged at
|
||||
* ERROR level with the specified cause.
|
||||
* <p>
|
||||
* This method never returns normally.
|
||||
*
|
||||
* @param message the message for the log and exception.
|
||||
* @param cause the causing exception (may be null).
|
||||
* @throws BugException always.
|
||||
*/
|
||||
public void throwBugException(String message, Throwable cause) throws BugException {
|
||||
BugException e = new BugException(message, cause);
|
||||
log(createLogLine(0, LogLevel.ERROR, message, cause));
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a LogLine object from the provided information. This method must be
|
||||
* called directly from the called method in order for the trace position
|
||||
* to be correct!
|
||||
*
|
||||
* @param additionalLevels how many additional stack trace levels to include on the line.
|
||||
* @param level the log level.
|
||||
* @param message the log message (null ok).
|
||||
* @param cause the log exception (null ok).
|
||||
*
|
||||
* @return a LogLine populated with all necessary fields.
|
||||
*/
|
||||
private LogLine createLogLine(int additionalLevels, LogLevel level, String message,
|
||||
Throwable cause) {
|
||||
TraceException trace;
|
||||
if (level.atLeast(TRACING_LOG_LEVEL)) {
|
||||
trace = new TraceException(2, 2 + additionalLevels);
|
||||
} else {
|
||||
trace = null;
|
||||
}
|
||||
return new LogLine(level, trace, message, cause);
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class LogLine implements Comparable<LogLine> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the level
|
||||
*/
|
||||
@ -92,14 +92,14 @@ public class LogLine implements Comparable<LogLine> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the trace
|
||||
*/
|
||||
public TraceException getTrace() {
|
||||
return trace;
|
||||
public String getLocation() {
|
||||
if (trace != null) {
|
||||
return trace.getLocation();
|
||||
} else {
|
||||
return "(-)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
@ -116,8 +116,8 @@ public class LogLine implements Comparable<LogLine> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return a formatted string of the log line. The line contains the log
|
||||
* line count, the time stamp, the log level, the trace position, the log
|
||||
@ -129,7 +129,7 @@ public class LogLine implements Comparable<LogLine> {
|
||||
String str;
|
||||
str = String.format("%4d %10.3f %-" + LogLevel.LENGTH + "s %s %s",
|
||||
count, timestamp / 1000.0, (level != null) ? level.toString() : "NULL",
|
||||
(trace != null) ? trace.getMessage() : "(-)",
|
||||
getLocation(),
|
||||
message);
|
||||
if (cause != null) {
|
||||
StackTraceWriter stw = new StackTraceWriter();
|
||||
|
@ -0,0 +1,56 @@
|
||||
package net.sf.openrocket.logging;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.classic.spi.ThrowableProxy;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
|
||||
public class LogbackBufferLoggerAdaptor extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private final LogHelper logHelper;
|
||||
|
||||
public LogbackBufferLoggerAdaptor() {
|
||||
logHelper = LoggingSystemSetup.getInstance();
|
||||
}
|
||||
|
||||
public LogbackBufferLoggerAdaptor(LogHelper logHelper) {
|
||||
this.logHelper = logHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void append(ILoggingEvent e) {
|
||||
e.getCallerData();
|
||||
LogLine ll = toLogLine(e);
|
||||
|
||||
logHelper.log(ll);
|
||||
}
|
||||
|
||||
private LogLevel toORLevel(Level l) {
|
||||
switch (l.toInt()) {
|
||||
case Level.TRACE_INT:
|
||||
return LogLevel.VBOSE;
|
||||
case Level.DEBUG_INT:
|
||||
return LogLevel.DEBUG;
|
||||
case Level.INFO_INT:
|
||||
return LogLevel.INFO;
|
||||
case Level.WARN_INT:
|
||||
return LogLevel.WARN;
|
||||
case Level.ERROR_INT:
|
||||
return LogLevel.ERROR;
|
||||
default:
|
||||
return LogLevel.ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
private LogLine toLogLine(ILoggingEvent e) {
|
||||
LogLevel l = toORLevel(e.getLevel());
|
||||
if (SLF4JLogHelper.USER_MARKER.equals(e.getMarker()))
|
||||
l = LogLevel.USER;
|
||||
Throwable t = null;
|
||||
if (e.getThrowableProxy() != null) {
|
||||
t = ((ThrowableProxy) e.getThrowableProxy()).getThrowable();
|
||||
}
|
||||
return new LogLine(l, new TraceException(), e.getMessage(), t);
|
||||
}
|
||||
|
||||
}
|
30
core/src/net/sf/openrocket/logging/LoggingSystemSetup.java
Normal file
30
core/src/net/sf/openrocket/logging/LoggingSystemSetup.java
Normal file
@ -0,0 +1,30 @@
|
||||
package net.sf.openrocket.logging;
|
||||
|
||||
|
||||
public class LoggingSystemSetup {
|
||||
|
||||
private static final DelegatorLogger delegator = new DelegatorLogger();
|
||||
|
||||
private static final int LOG_BUFFER_LENGTH = 50;
|
||||
|
||||
private static final LogLevelBufferLogger llbl = new LogLevelBufferLogger(LOG_BUFFER_LENGTH);
|
||||
|
||||
static {
|
||||
delegator.addLogger(llbl);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logger to be used in logging.
|
||||
*
|
||||
* @return the logger to be used in all logging.
|
||||
*/
|
||||
public static DelegatorLogger getInstance() {
|
||||
return delegator;
|
||||
}
|
||||
|
||||
public static LogLevelBufferLogger getBufferLogger() {
|
||||
return llbl;
|
||||
}
|
||||
|
||||
}
|
38
core/src/net/sf/openrocket/logging/SLF4JLogHelper.java
Normal file
38
core/src/net/sf/openrocket/logging/SLF4JLogHelper.java
Normal file
@ -0,0 +1,38 @@
|
||||
package net.sf.openrocket.logging;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.Marker;
|
||||
import org.slf4j.MarkerFactory;
|
||||
|
||||
public class SLF4JLogHelper extends DelegatorLogger {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SLF4JLogHelper.class);
|
||||
static final Marker USER_MARKER = MarkerFactory.getMarker("User");
|
||||
|
||||
@Override
|
||||
public void log(LogLine line) {
|
||||
super.log(line);
|
||||
switch (line.getLevel()) {
|
||||
case VBOSE:
|
||||
log.trace(line.getMessage(), line.getCause());
|
||||
break;
|
||||
case DEBUG:
|
||||
log.debug(line.getMessage(), line.getCause());
|
||||
break;
|
||||
case INFO:
|
||||
log.info(line.getMessage(), line.getCause());
|
||||
break;
|
||||
case USER:
|
||||
log.info(USER_MARKER, line.getMessage(), line.getCause());
|
||||
break;
|
||||
case WARN:
|
||||
log.warn(line.getMessage(), line.getCause());
|
||||
break;
|
||||
case ERROR:
|
||||
log.error(line.getMessage(), line.getCause());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,97 +2,33 @@ package net.sf.openrocket.logging;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An exception that is used to store a stack trace. On modern computers
|
||||
* instantiation of an exception takes on the order of one microsecond, while
|
||||
* examining the trace typically takes several times longer. Therefore the
|
||||
* exception should be stored and the stack trace examined only when necessary.
|
||||
* <p>
|
||||
* The {@link #getMessage()} method returns a description of the position
|
||||
* where this exception has been instantiated. The position is provided
|
||||
* as many levels upwards from the instantiation position as provided to the
|
||||
* constructor.
|
||||
* The {@link #getLocation()} method returns a description of the position
|
||||
* where this exception has been instantiated.
|
||||
*
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
*/
|
||||
public class TraceException extends Exception {
|
||||
class TraceException {
|
||||
|
||||
private static final String STANDARD_PACKAGE_PREFIX = "net.sf.openrocket.";
|
||||
private static final String EXCLUDED_PACKAGE_PREFIX = "net.sf.openrocket.logging";
|
||||
|
||||
private final int minLevel;
|
||||
private final int maxLevel;
|
||||
private volatile String message = null;
|
||||
private final Throwable t;
|
||||
private volatile String location;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate exception that provides the line of instantiation as a message.
|
||||
*/
|
||||
public TraceException() {
|
||||
this(0, 0);
|
||||
TraceException() {
|
||||
t = new Throwable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate exception that provides the provided number of levels upward
|
||||
* from the instantiation location as a message. The level provided
|
||||
* is how many levels upward should be examined to find the stack trace
|
||||
* position for the exception message.
|
||||
*
|
||||
* @param level how many levels upward to examine the stack trace to find
|
||||
* the correct message.
|
||||
*/
|
||||
public TraceException(int level) {
|
||||
this(level, level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate exception that provides a range of levels upward from the
|
||||
* instantiation location as a message. This is useful to identify the
|
||||
* next level of callers upward.
|
||||
*
|
||||
* @param minLevel the first level which to include.
|
||||
* @param maxLevel the last level which to include.
|
||||
*/
|
||||
public TraceException(int minLevel, int maxLevel) {
|
||||
if (minLevel > maxLevel || minLevel < 0) {
|
||||
throw new IllegalArgumentException("minLevel=" + minLevel + " maxLevel=" + maxLevel);
|
||||
}
|
||||
this.minLevel = minLevel;
|
||||
this.maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct an exception with the specified message.
|
||||
*
|
||||
* @param message the message for the exception.
|
||||
*/
|
||||
public TraceException(String message) {
|
||||
this(0, 0);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct an exception with the specified message and cause.
|
||||
*
|
||||
* @param message the message for the exception.
|
||||
* @param cause the cause for this exception.
|
||||
*/
|
||||
public TraceException(String message, Throwable cause) {
|
||||
this(0, 0);
|
||||
this.message = message;
|
||||
this.initCause(cause);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the description of the code position as provided in the constructor.
|
||||
*/
|
||||
@Override
|
||||
public String getMessage() {
|
||||
if (message == null) {
|
||||
StackTraceElement[] elements = this.getStackTrace();
|
||||
public String getLocation() {
|
||||
if (location == null) {
|
||||
StackTraceElement[] elements = t.getStackTrace();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('(');
|
||||
@ -101,30 +37,35 @@ public class TraceException extends Exception {
|
||||
sb.append("no stack trace");
|
||||
} else {
|
||||
|
||||
int levelCount = 0;
|
||||
int position = minLevel;
|
||||
while (levelCount <= (maxLevel - minLevel) && position < elements.length) {
|
||||
int found = -1;
|
||||
int index = 0;
|
||||
while (found < 0 && index < elements.length) {
|
||||
|
||||
// Ignore synthetic "access$0" methods generated by the JRE
|
||||
if (elements[position].getMethodName().contains("$")) {
|
||||
position++;
|
||||
if (elements[index].getMethodName().contains("$")) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (levelCount > 0) {
|
||||
sb.append(' ');
|
||||
String className = elements[index].getClassName();
|
||||
if (!className.startsWith(EXCLUDED_PACKAGE_PREFIX) && className.startsWith(STANDARD_PACKAGE_PREFIX)) {
|
||||
sb.append(toString(elements[index]));
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
sb.append(toString(elements[position]));
|
||||
levelCount++;
|
||||
position++;
|
||||
|
||||
index++;
|
||||
|
||||
}
|
||||
if (found < 0) {
|
||||
sb.append(toString(elements[0]));
|
||||
}
|
||||
|
||||
}
|
||||
sb.append(')');
|
||||
|
||||
message = sb.toString();
|
||||
location = sb.toString();
|
||||
}
|
||||
return message;
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,10 +8,7 @@ import net.sf.openrocket.l10n.ClassBasedTranslator;
|
||||
import net.sf.openrocket.l10n.DebugTranslator;
|
||||
import net.sf.openrocket.l10n.ExceptionSuppressingTranslator;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.logging.LogLevel;
|
||||
import net.sf.openrocket.logging.LogLevelBufferLogger;
|
||||
import net.sf.openrocket.logging.PrintStreamLogger;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
|
||||
@ -22,9 +19,6 @@ import com.google.inject.Injector;
|
||||
*/
|
||||
public final class Application {
|
||||
|
||||
private static LogHelper logger;
|
||||
private static LogLevelBufferLogger logBuffer;
|
||||
|
||||
private static Translator baseTranslator = new DebugTranslator(null);
|
||||
|
||||
private static ComponentPresetDao componentPresetDao;
|
||||
@ -52,44 +46,10 @@ public final class Application {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the logger to be used in logging. By default this returns
|
||||
* a logger that outputs to stdout/stderr even if not separately initialized,
|
||||
* useful for development and debugging.
|
||||
*/
|
||||
public static LogHelper getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the logger to be used in logging. Note that calling this will only have effect
|
||||
* on not-yet loaded classes, as the instance is stored in a static variable.
|
||||
*/
|
||||
public static void setLogger(LogHelper logger) {
|
||||
Application.logger = logger;
|
||||
}
|
||||
|
||||
public static WatchService getWatchService() {
|
||||
return Application.injector.getInstance(WatchService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the log buffer.
|
||||
*
|
||||
* @return the logBuffer or null if not initialized
|
||||
*/
|
||||
public static LogLevelBufferLogger getLogBuffer() {
|
||||
return logBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log buffer logger. The logger must be separately configured
|
||||
* to receive the logging.
|
||||
*/
|
||||
public static void setLogBuffer(LogLevelBufferLogger logBuffer) {
|
||||
Application.logBuffer = logBuffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the logging to output the specified log level and upwards to standard output.
|
||||
@ -97,13 +57,15 @@ public final class Application {
|
||||
* @param level the minimum logging level to output.
|
||||
*/
|
||||
public static void setLogOutputLevel(LogLevel level) {
|
||||
// FIXME
|
||||
/*
|
||||
logger = new PrintStreamLogger();
|
||||
for (LogLevel l : LogLevel.values()) {
|
||||
if (l.atLeast(level)) {
|
||||
((PrintStreamLogger) logger).setOutput(l, System.out);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,6 @@ import net.sf.openrocket.formatting.RocketDescriptorImpl;
|
||||
import net.sf.openrocket.gui.watcher.WatchService;
|
||||
import net.sf.openrocket.gui.watcher.WatchServiceImpl;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
@ -13,7 +12,6 @@ public class ApplicationModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(LogHelper.class).toInstance(Application.getLogger());
|
||||
bind(Preferences.class).toInstance(Application.getPreferences());
|
||||
bind(Translator.class).toInstance(Application.getTranslator());
|
||||
bind(WatchService.class).to(WatchServiceImpl.class);
|
||||
|
@ -23,9 +23,11 @@ import net.sf.openrocket.gui.main.SwingExceptionHandler;
|
||||
import net.sf.openrocket.gui.util.BlockingMotorDatabaseProvider;
|
||||
import net.sf.openrocket.gui.util.GUIUtil;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.util.BuildProperties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
@ -41,8 +43,8 @@ import com.google.inject.Injector;
|
||||
*/
|
||||
public class ApplicationStartup {
|
||||
|
||||
@Inject
|
||||
private LogHelper log;
|
||||
private final static Logger log = LoggerFactory.getLogger(ApplicationStartup.class);
|
||||
|
||||
@Inject
|
||||
private Injector injector;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
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;
|
||||
@ -11,13 +9,13 @@ import net.sf.openrocket.l10n.DebugTranslator;
|
||||
import net.sf.openrocket.l10n.L10N;
|
||||
import net.sf.openrocket.l10n.ResourceBundleTranslator;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.logging.DelegatorLogger;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.logging.LogLevel;
|
||||
import net.sf.openrocket.logging.LogLevelBufferLogger;
|
||||
import net.sf.openrocket.logging.PrintStreamLogger;
|
||||
import net.sf.openrocket.plugin.PluginModule;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
@ -40,12 +38,7 @@ import com.google.inject.Module;
|
||||
*/
|
||||
public class GuiceStartup {
|
||||
|
||||
static LogHelper log;
|
||||
|
||||
private static final String LOG_STDERR_PROPERTY = "openrocket.log.stderr";
|
||||
private static final String LOG_STDOUT_PROPERTY = "openrocket.log.stdout";
|
||||
|
||||
private static final int LOG_BUFFER_LENGTH = 50;
|
||||
private final static Logger log = LoggerFactory.getLogger(GuiceStartup.class);
|
||||
|
||||
/**
|
||||
* OpenRocket startup main method.
|
||||
@ -76,8 +69,6 @@ public class GuiceStartup {
|
||||
*/
|
||||
private static void checkDebugStatus() {
|
||||
if (System.getProperty("openrocket.debug") != null) {
|
||||
setPropertyIfNotSet("openrocket.log.stdout", "VBOSE");
|
||||
setPropertyIfNotSet("openrocket.log.tracelevel", "VBOSE");
|
||||
setPropertyIfNotSet("openrocket.debug.menu", "true");
|
||||
setPropertyIfNotSet("openrocket.debug.mutexlocation", "true");
|
||||
setPropertyIfNotSet("openrocket.debug.motordigest", "true");
|
||||
@ -97,7 +88,7 @@ public class GuiceStartup {
|
||||
* Initializes the loggins system.
|
||||
*/
|
||||
public static void initializeLogging() {
|
||||
DelegatorLogger delegator = new DelegatorLogger();
|
||||
/*DelegatorLogger delegator = new DelegatorLogger();
|
||||
|
||||
// Log buffer
|
||||
LogLevelBufferLogger buffer = new LogLevelBufferLogger(LOG_BUFFER_LENGTH);
|
||||
@ -135,7 +126,6 @@ public class GuiceStartup {
|
||||
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.
|
||||
@ -167,6 +157,7 @@ public class GuiceStartup {
|
||||
}
|
||||
}
|
||||
}));
|
||||
*/
|
||||
}
|
||||
|
||||
private static boolean setLogOutput(PrintStreamLogger logger, PrintStream stream, String level, LogLevel defaultLevel) {
|
||||
|
@ -15,13 +15,13 @@ import net.sf.openrocket.file.iterator.FileIterator;
|
||||
import net.sf.openrocket.file.motor.GeneralMotorLoader;
|
||||
import net.sf.openrocket.gui.util.SimpleFileFilter;
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||
import net.sf.openrocket.util.BugException;
|
||||
import net.sf.openrocket.util.Pair;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* An asynchronous database loader that loads the internal thrust curves
|
||||
@ -31,12 +31,12 @@ import com.google.inject.Inject;
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
*/
|
||||
public class MotorDatabaseLoader extends AsynchronousDatabaseLoader {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(MotorDatabaseLoader.class);
|
||||
|
||||
private static final String THRUSTCURVE_DIRECTORY = "datafiles/thrustcurves/";
|
||||
private static final long STARTUP_DELAY = 0;
|
||||
|
||||
@Inject
|
||||
private LogHelper log;
|
||||
|
||||
private final ThrustCurveMotorSetDatabase database = new ThrustCurveMotorSetDatabase();
|
||||
private int motorCount = 0;
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class SerializePresets {
|
||||
|
||||
List<ComponentPreset> list = componentPresetDao.listAll();
|
||||
|
||||
Application.getLogger().info("Total number of presets = " + list.size());
|
||||
System.out.println("Total number of presets = " + list.size());
|
||||
|
||||
File outFile = new File("resources/datafiles/presets", "system.ser");
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
package net.sf.openrocket.util;
|
||||
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
/**
|
||||
* A class that performs object invalidation functions.
|
||||
*
|
||||
@ -17,7 +16,7 @@ public class Invalidator implements Invalidatable {
|
||||
private static final Logger log = LoggerFactory.getLogger(Invalidator.class);
|
||||
|
||||
private final Object monitorable;
|
||||
private TraceException invalidated = null;
|
||||
private Throwable invalidated = null;
|
||||
|
||||
|
||||
/**
|
||||
@ -45,7 +44,7 @@ public class Invalidator implements Invalidatable {
|
||||
throw new BugException(monitorable + ": This object has been invalidated", invalidated);
|
||||
} else {
|
||||
log.warn(monitorable + ": This object has been invalidated",
|
||||
new TraceException("Usage was attempted here", invalidated));
|
||||
new Throwable("Usage was attempted here", invalidated));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -68,7 +67,7 @@ public class Invalidator implements Invalidatable {
|
||||
if (invalidated != null) {
|
||||
log.warn(monitorable + ": This object has already been invalidated, ignoring", invalidated);
|
||||
}
|
||||
invalidated = new TraceException("Invalidation occurred here");
|
||||
invalidated = new Throwable("Invalidation occurred here");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,6 @@ import java.util.Iterator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
|
||||
/**
|
||||
* A list of listeners of a specific type. This class contains various utility,
|
||||
* safety and debugging methods for handling listeners.
|
||||
@ -23,19 +21,18 @@ public class ListenerList<T> implements Invalidatable, Iterable<T> {
|
||||
private static final Logger log = LoggerFactory.getLogger(ListenerList.class);
|
||||
|
||||
private final ArrayList<ListenerData<T>> listeners = new ArrayList<ListenerData<T>>();
|
||||
private final TraceException instantiationLocation;
|
||||
private final Throwable instantiationLocation;
|
||||
|
||||
private TraceException invalidated = null;
|
||||
private Throwable invalidated = null;
|
||||
|
||||
|
||||
/**
|
||||
* Sole contructor.
|
||||
*/
|
||||
public ListenerList() {
|
||||
this.instantiationLocation = new TraceException(1, 1);
|
||||
this.instantiationLocation = new Throwable();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the specified listener to this list. The listener is not added if it
|
||||
* already is in the list (checked by the equality operator ==). This method throws
|
||||
@ -105,7 +102,7 @@ public class ListenerList<T> implements Invalidatable, Iterable<T> {
|
||||
* Return the instantiation location of this listener list.
|
||||
* @return the location where this listener list was instantiated.
|
||||
*/
|
||||
public TraceException getInstantiationLocation() {
|
||||
public Throwable getInstantiationLocation() {
|
||||
return instantiationLocation;
|
||||
}
|
||||
|
||||
@ -117,7 +114,7 @@ public class ListenerList<T> implements Invalidatable, Iterable<T> {
|
||||
*/
|
||||
@Override
|
||||
public void invalidate() {
|
||||
this.invalidated = new TraceException("Invalidation occurred at this point");
|
||||
this.invalidated = new Throwable("Invalidation occurred at this point");
|
||||
if (!listeners.isEmpty()) {
|
||||
log.info("Invalidating " + this + " while still having listeners " + listeners);
|
||||
}
|
||||
@ -136,7 +133,7 @@ public class ListenerList<T> implements Invalidatable, Iterable<T> {
|
||||
throw new BugException(this + ": this ListenerList has been invalidated", invalidated);
|
||||
} else {
|
||||
log.warn(this + ": this ListenerList has been invalidated",
|
||||
new TraceException("ListenerList was attempted to be used here", invalidated));
|
||||
new Throwable("ListenerList was attempted to be used here", invalidated));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,7 +175,7 @@ public class ListenerList<T> implements Invalidatable, Iterable<T> {
|
||||
public static class ListenerData<T> {
|
||||
private final T listener;
|
||||
private final long addTimestamp;
|
||||
private final TraceException addLocation;
|
||||
private final Throwable addLocation;
|
||||
private long accessTimestamp;
|
||||
|
||||
/**
|
||||
@ -191,7 +188,7 @@ public class ListenerList<T> implements Invalidatable, Iterable<T> {
|
||||
this.listener = listener;
|
||||
this.addTimestamp = System.currentTimeMillis();
|
||||
this.accessTimestamp = this.addTimestamp;
|
||||
this.addLocation = new TraceException("Listener " + listener + " add position");
|
||||
this.addLocation = new Throwable("Listener " + listener + " add position");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -227,7 +224,7 @@ public class ListenerList<T> implements Invalidatable, Iterable<T> {
|
||||
/**
|
||||
* Return the location where this listener was added to the listener list.
|
||||
*/
|
||||
public TraceException getAddLocation() {
|
||||
public Throwable getAddLocation() {
|
||||
return addLocation;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.sf.openrocket.util;
|
||||
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
|
||||
/**
|
||||
* A utility class helping an object to be made immutable after a certain point of time.
|
||||
@ -15,7 +14,7 @@ import net.sf.openrocket.logging.TraceException;
|
||||
*/
|
||||
public class Mutable implements Cloneable {
|
||||
|
||||
private TraceException immuteTrace = null;
|
||||
private Throwable immuteTrace = null;
|
||||
|
||||
/**
|
||||
* Mark the object immutable. Once the object has been called the object
|
||||
@ -23,7 +22,7 @@ public class Mutable implements Cloneable {
|
||||
*/
|
||||
public void immute() {
|
||||
if (immuteTrace == null) {
|
||||
immuteTrace = new TraceException(1, 2);
|
||||
immuteTrace = new Throwable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,11 @@ package net.sf.openrocket.util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
|
||||
/**
|
||||
* A mutex that can be used for verifying thread safety. This class cannot be
|
||||
* used to perform synchronization, only to detect concurrency issues. This
|
||||
@ -37,7 +36,7 @@ public abstract class SafetyMutex {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Verify that this mutex is unlocked, but don't lock it. This has the same effect
|
||||
* as <code>mutex.lock(); mutex.unlock();</code> and is useful for methods that return
|
||||
@ -73,7 +72,7 @@ public abstract class SafetyMutex {
|
||||
public abstract boolean unlock(String location);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Bogus implementation of a safety mutex (used when safety checking is not performed).
|
||||
*/
|
||||
@ -106,12 +105,12 @@ public abstract class SafetyMutex {
|
||||
// lockingThread is set when this mutex is locked.
|
||||
Thread lockingThread = null;
|
||||
// longingLocation is set when lockingThread is, if STORE_LOCKING_LOCATION is true
|
||||
TraceException lockingLocation = null;
|
||||
Throwable lockingLocation = null;
|
||||
// Stack of places that have locked this mutex
|
||||
final LinkedList<String> locations = new LinkedList<String>();
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void verify() {
|
||||
checkState(true);
|
||||
@ -121,7 +120,7 @@ public abstract class SafetyMutex {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void lock(String location) {
|
||||
if (location == null) {
|
||||
@ -136,14 +135,14 @@ public abstract class SafetyMutex {
|
||||
|
||||
lockingThread = currentThread;
|
||||
if (STORE_LOCKING_LOCATION) {
|
||||
lockingLocation = new TraceException("Location where mutex was locked '" + location + "'");
|
||||
lockingLocation = new Throwable("Location where mutex was locked '" + location + "'");
|
||||
}
|
||||
locations.push(location);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean unlock(String location) {
|
||||
try {
|
||||
@ -154,7 +153,7 @@ public abstract class SafetyMutex {
|
||||
}
|
||||
checkState(false);
|
||||
|
||||
|
||||
|
||||
// Check that the mutex is locked
|
||||
if (lockingThread == null) {
|
||||
error("Mutex was not locked", false);
|
||||
@ -189,7 +188,7 @@ public abstract class SafetyMutex {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check that the internal state of the mutex (lockingThread vs. locations) is correct.
|
||||
*/
|
||||
|
@ -5,35 +5,54 @@ import static org.junit.Assert.assertEquals;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
|
||||
public class LogLevelBufferLoggerTest {
|
||||
|
||||
// NOTE cast
|
||||
private final static Logger logger = (Logger) LoggerFactory.getLogger(LogLevelBufferLoggerTest.class);
|
||||
|
||||
@Test
|
||||
public void testLogger() {
|
||||
LogLevelBufferLogger logger = new LogLevelBufferLogger(4);
|
||||
|
||||
DelegatorLogger l = new DelegatorLogger();
|
||||
LogLevelBufferLogger llbl = new LogLevelBufferLogger(4);
|
||||
|
||||
// assume SLF4J is bound to logback in the current environment
|
||||
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
|
||||
// Call context.reset() to clear any previous configuration, e.g. default
|
||||
// configuration. For multi-step configuration, omit calling context.reset().
|
||||
context.reset();
|
||||
LogbackBufferLoggerAdaptor a = new LogbackBufferLoggerAdaptor(llbl);
|
||||
a.start();
|
||||
logger.addAppender(a);
|
||||
|
||||
logger.debug("debug 1");
|
||||
logger.debug("debug 2");
|
||||
logger.user("user 1");
|
||||
logger.info(Markers.USER_MARKER, "user 1");
|
||||
logger.info("info 1");
|
||||
logger.info("info 2");
|
||||
logger.warn("warn 1");
|
||||
logger.debug("debug 3");
|
||||
logger.debug("debug 4");
|
||||
logger.user("user 2");
|
||||
logger.info(Markers.USER_MARKER, "user 2");
|
||||
logger.info("info 3");
|
||||
logger.error("error 1");
|
||||
logger.debug("debug 5");
|
||||
logger.warn("warn 2");
|
||||
logger.debug("debug 6");
|
||||
logger.user("user 3");
|
||||
logger.info(Markers.USER_MARKER, "user 3");
|
||||
logger.info("info 4");
|
||||
logger.debug("debug 7");
|
||||
logger.info("info 5");
|
||||
logger.debug("debug 8");
|
||||
logger.info("info 6");
|
||||
|
||||
List<LogLine> list = logger.getLogs();
|
||||
List<LogLine> list = llbl.getLogs();
|
||||
assertEquals(16, list.size());
|
||||
|
||||
assertEquals("user 1", list.get(0).getMessage());
|
||||
@ -54,5 +73,4 @@ public class LogLevelBufferLoggerTest {
|
||||
assertEquals("info 6", list.get(15).getMessage());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,63 +0,0 @@
|
||||
package net.sf.openrocket.logging;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LoggingTest {
|
||||
|
||||
@Test
|
||||
public void testLoggers() {
|
||||
// Ensure a sane stack trace
|
||||
actualTest();
|
||||
}
|
||||
|
||||
private void actualTest() {
|
||||
BufferLogger log3 = new BufferLogger(3);
|
||||
BufferLogger log4 = new BufferLogger(4);
|
||||
|
||||
DelegatorLogger delegator = new DelegatorLogger();
|
||||
delegator.addLogger(log3);
|
||||
delegator.addLogger(log4);
|
||||
|
||||
delegator.debug("one");
|
||||
delegator.debug("two");
|
||||
delegator.info("three");
|
||||
delegator.warn(1, "four");
|
||||
delegator.error("five");
|
||||
|
||||
List<LogLine> logs = log4.getLogs();
|
||||
assertEquals(4, logs.size());
|
||||
assertTrue(logs.get(0).toString(), logs.get(0).toString().matches(
|
||||
" *[0-9]+ +[0-9]+\\.[0-9]+ +DEBUG \\(-\\) two"));
|
||||
assertTrue(logs.get(1).toString(), logs.get(1).toString().matches(
|
||||
" *[0-9]+ +[0-9]+\\.[0-9]+ +INFO \\(LoggingTest.java:[0-9]+\\) three"));
|
||||
assertTrue(logs.get(2).toString(), logs.get(2).toString().matches(
|
||||
" *[0-9]+ +[0-9]+\\.[0-9]+ +WARN \\(LoggingTest.java:[0-9]+ LoggingTest.java:[0-9]+\\) four"));
|
||||
assertTrue(logs.get(3).toString(), logs.get(3).toString().matches(
|
||||
" *[0-9]+ +[0-9]+\\.[0-9]+ +ERROR \\(LoggingTest.java:[0-9]+\\) five"));
|
||||
|
||||
logs = log3.getLogs();
|
||||
assertEquals(3, logs.size());
|
||||
assertTrue(logs.get(0).toString(), logs.get(0).toString().matches(
|
||||
" *[0-9]+ +[0-9]+\\.[0-9]+ +INFO \\(LoggingTest.java:[0-9]+\\) three"));
|
||||
assertTrue(logs.get(1).toString(), logs.get(1).toString().matches(
|
||||
" *[0-9]+ +[0-9]+\\.[0-9]+ +WARN \\(LoggingTest.java:[0-9]+ LoggingTest.java:[0-9]+\\) four"));
|
||||
assertTrue(logs.get(2).toString(), logs.get(2).toString().matches(
|
||||
" *[0-9]+ +[0-9]+\\.[0-9]+ +ERROR \\(LoggingTest.java:[0-9]+\\) five"));
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PrintStreamLogger logger = new PrintStreamLogger();
|
||||
|
||||
logger.debug("a debug message");
|
||||
logger.info("an info message");
|
||||
logger.warn("a warning message");
|
||||
logger.error("an error message");
|
||||
|
||||
logger.debug(4, "Debugging");
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package net.sf.openrocket.logging;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TraceExceptionTest {
|
||||
|
||||
private TraceException getViaAccess() {
|
||||
|
||||
/*
|
||||
* The SubClass test bases on the fact that getViaAccess method is defined on a row number < 20
|
||||
* and the return statement is on a row number > 20.
|
||||
*
|
||||
* The JRE sometimes adds an additional "access$NNN" method call between the calls with the
|
||||
* row number equal to the method definition line.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
return new TraceException(0, 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBasic() {
|
||||
TraceException trace = new TraceException();
|
||||
assertMatch("\\(TraceExceptionTest.java:[2-9][0-9]\\)", trace);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOneLevelUp() {
|
||||
// @formatter:off - these need to be on the same line number
|
||||
TraceException trace = getOneLevelUp(); TraceException ref = new TraceException();
|
||||
// @formatter:on
|
||||
assertEquals(ref.getMessage(), trace.getMessage());
|
||||
}
|
||||
|
||||
private TraceException getOneLevelUp() {
|
||||
return new TraceException(1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTwoLevels() {
|
||||
TraceException trace = getTwoLevels();
|
||||
assertMatch("\\(TraceExceptionTest.java:[2-9][0-9] TraceExceptionTest.java:[2-9][0-9]\\)", trace);
|
||||
}
|
||||
|
||||
private TraceException getTwoLevels() {
|
||||
return new TraceException(0, 1);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testViaSubclass() {
|
||||
/*
|
||||
* This tests that TraceException.getMessage ignores the synthetic "access$0" method calls.
|
||||
*/
|
||||
|
||||
TraceException trace = new SubClass().getTrace();
|
||||
assertMatch("\\(TraceExceptionTest.java:[2-9][0-9] TraceExceptionTest.java:[2-9][0-9]\\)", trace);
|
||||
}
|
||||
|
||||
private class SubClass {
|
||||
private TraceException getTrace() {
|
||||
return getViaAccess();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void assertMatch(String regex, TraceException trace) {
|
||||
boolean match = trace.getMessage().matches(regex);
|
||||
if (!match) {
|
||||
trace.printStackTrace();
|
||||
assertTrue("Was: " + trace.getMessage(), match);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,9 +7,7 @@ import java.util.BitSet;
|
||||
import java.util.EventObject;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sf.openrocket.logging.LogHelper;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.StateChangeListener;
|
||||
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
||||
|
||||
@ -175,8 +173,6 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
@Test
|
||||
public void testGeneralMethods() {
|
||||
|
||||
LogHelper log = Application.getLogger();
|
||||
|
||||
/* Setup */
|
||||
Rocket r1 = makeSingleStageTestRocket();
|
||||
Configuration config = r1.getDefaultConfiguration();
|
||||
@ -197,9 +193,9 @@ public class ConfigurationTest extends BaseTestCase {
|
||||
double refArea = config.getReferenceArea();
|
||||
|
||||
// TODO validate that the values are correct
|
||||
log.debug("ConfigurationTest, length: " + String.valueOf(length));
|
||||
log.debug("ConfigurationTest, refLength: " + String.valueOf(refLength));
|
||||
log.debug("ConfigurationTest, refArea: " + String.valueOf(refArea));
|
||||
//log.debug("ConfigurationTest, length: " + String.valueOf(length));
|
||||
//log.debug("ConfigurationTest, refLength: " + String.valueOf(refLength));
|
||||
//log.debug("ConfigurationTest, refArea: " + String.valueOf(refArea));
|
||||
|
||||
/* Cleanup */
|
||||
config.release();
|
||||
|
@ -1,7 +1,8 @@
|
||||
package net.sf.openrocket.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import net.sf.openrocket.logging.TraceException;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -24,7 +25,7 @@ public class MutableTest {
|
||||
} catch (IllegalStateException e) {
|
||||
// Success
|
||||
t = e.getCause();
|
||||
assertTrue(t instanceof TraceException);
|
||||
assertTrue(t instanceof Throwable);
|
||||
}
|
||||
|
||||
m.immute();
|
||||
|
Loading…
x
Reference in New Issue
Block a user