diff --git a/pom.xml b/pom.xml index 7dc2878..ac2c3f4 100644 --- a/pom.xml +++ b/pom.xml @@ -126,6 +126,15 @@ imagej-utils ${imagej-utils.version} + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + test + org.junit.jupiter junit-jupiter diff --git a/src/main/java/de/embl/schwab/crosshair/io/STLResourceLoader.java b/src/main/java/de/embl/schwab/crosshair/io/STLResourceLoader.java index 5ac979c..fa62254 100644 --- a/src/main/java/de/embl/schwab/crosshair/io/STLResourceLoader.java +++ b/src/main/java/de/embl/schwab/crosshair/io/STLResourceLoader.java @@ -2,8 +2,9 @@ import customnode.CustomMesh; import customnode.CustomTriangleMesh; -import ij.IJ; import org.scijava.vecmath.Point3f; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; import java.util.ArrayList; @@ -17,6 +18,9 @@ * input stream, and load from resource name */ public class STLResourceLoader { + + private static final Logger logger = LoggerFactory.getLogger(STLResourceLoader.class); + private HashMap meshes; private ArrayList vertices = new ArrayList(); private String name = null; @@ -35,7 +39,7 @@ public static Map loadSTL(String name) { try { return STLResourceLoader.load(name); } catch (Exception var2) { - var2.printStackTrace(); + logger.error("Error loading STL file", var2); return null; } } @@ -52,7 +56,7 @@ public static Map load(String name) throws IOException { try { sl.parse(name); } catch (RuntimeException var3) { - IJ.log("error reading " + sl.name); + logger.error("error reading " + sl.name); throw var3; } @@ -101,8 +105,7 @@ private void parseBinary() { inputStream.close(); } catch (IOException var10) { - var10.printStackTrace(); - + logger.error("Error parsing binary", var10); } CustomMesh cm = this.createCustomMesh(); diff --git a/src/main/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReader.java b/src/main/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReader.java index c54cbab..7b20faa 100644 --- a/src/main/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReader.java +++ b/src/main/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReader.java @@ -1,6 +1,8 @@ package de.embl.schwab.crosshair.legacy; import com.google.gson.Gson; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.FileReader; @@ -11,6 +13,8 @@ */ public class OldFormatSettingsReader { + private static final Logger logger = LoggerFactory.getLogger(OldFormatSettingsReader.class); + /** * Create a settings reader */ @@ -26,7 +30,7 @@ public OldFormatSettings readSettings( String filePath ) { try ( FileReader fileReader = new FileReader(filePath) ) { return gson.fromJson(fileReader, OldFormatSettings.class); } catch (IOException e) { - e.printStackTrace(); + logger.error("Error reading settings", e); } return null; diff --git a/src/main/java/de/embl/schwab/crosshair/settings/SettingsReader.java b/src/main/java/de/embl/schwab/crosshair/settings/SettingsReader.java index 2be830e..4547e34 100644 --- a/src/main/java/de/embl/schwab/crosshair/settings/SettingsReader.java +++ b/src/main/java/de/embl/schwab/crosshair/settings/SettingsReader.java @@ -12,6 +12,8 @@ import de.embl.schwab.crosshair.ui.swing.OtherPanel; import ij.IJ; import ij3d.Content; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.FileReader; import java.io.IOException; @@ -20,6 +22,8 @@ public class SettingsReader { + private static final Logger logger = LoggerFactory.getLogger(SettingsReader.class); + public SettingsReader() {} public Settings readSettings(String filePath ) { @@ -30,7 +34,7 @@ public Settings readSettings(String filePath ) { try ( FileReader fileReader = new FileReader(filePath) ) { return gson.fromJson(fileReader, Settings.class); } catch (IOException e1) { - e1.printStackTrace(); + logger.error("Error reading settings file", e1); } return null; diff --git a/src/main/java/de/embl/schwab/crosshair/settings/SettingsWriter.java b/src/main/java/de/embl/schwab/crosshair/settings/SettingsWriter.java index 1416861..2149340 100644 --- a/src/main/java/de/embl/schwab/crosshair/settings/SettingsWriter.java +++ b/src/main/java/de/embl/schwab/crosshair/settings/SettingsWriter.java @@ -5,6 +5,8 @@ import de.embl.schwab.crosshair.plane.Plane; import de.embl.schwab.crosshair.plane.PlaneManager; import ij3d.Content; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.FileWriter; import java.io.IOException; @@ -13,6 +15,8 @@ public class SettingsWriter { + private static final Logger logger = LoggerFactory.getLogger(SettingsWriter.class); + public SettingsWriter() { } public Settings createSettings(PlaneManager planeManager, Map imageNameToContent ) { @@ -58,7 +62,7 @@ public void writeSettings( Settings settings, String filePath ) { fileWriter.flush(); fileWriter.close(); } catch (IOException e1) { - e1.printStackTrace(); + logger.error("Error writing settings", e1); } } } diff --git a/src/main/java/de/embl/schwab/crosshair/solution/SolutionReader.java b/src/main/java/de/embl/schwab/crosshair/solution/SolutionReader.java index f82782d..26ff824 100644 --- a/src/main/java/de/embl/schwab/crosshair/solution/SolutionReader.java +++ b/src/main/java/de/embl/schwab/crosshair/solution/SolutionReader.java @@ -5,11 +5,16 @@ import com.google.gson.reflect.TypeToken; import de.embl.schwab.crosshair.io.serialise.VertexPointAdapter; import de.embl.schwab.crosshair.points.VertexPoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.FileReader; import java.io.IOException; public class SolutionReader { + + private static final Logger logger = LoggerFactory.getLogger(SolutionReader.class); + public SolutionReader() {} public Solution readSolution( String filePath ) { @@ -19,7 +24,7 @@ public Solution readSolution( String filePath ) { try ( FileReader fileReader = new FileReader(filePath) ) { return gson.fromJson(fileReader, Solution.class); } catch (IOException e) { - e.printStackTrace(); + logger.error("Error reading solutions file", e); } return null; diff --git a/src/main/java/de/embl/schwab/crosshair/solution/SolutionWriter.java b/src/main/java/de/embl/schwab/crosshair/solution/SolutionWriter.java index 49d2de8..43d126e 100644 --- a/src/main/java/de/embl/schwab/crosshair/solution/SolutionWriter.java +++ b/src/main/java/de/embl/schwab/crosshair/solution/SolutionWriter.java @@ -5,13 +5,16 @@ import com.google.gson.reflect.TypeToken; import de.embl.schwab.crosshair.io.serialise.VertexPointAdapter; import de.embl.schwab.crosshair.points.VertexPoint; -import de.embl.schwab.crosshair.solution.Solution; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.FileWriter; import java.io.IOException; public class SolutionWriter { + private static final Logger logger = LoggerFactory.getLogger(SolutionWriter.class); + private Solution solution; private String filePath; @@ -29,7 +32,7 @@ public void writeSolution() { fileWriter.flush(); fileWriter.close(); } catch (IOException e1) { - e1.printStackTrace(); + logger.error("Error writing solution", e1); } } diff --git a/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/AccuracyCalculator.java b/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/AccuracyCalculator.java index cfa3139..1f6dd84 100644 --- a/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/AccuracyCalculator.java +++ b/src/main/java/de/embl/schwab/crosshair/targetingaccuracy/AccuracyCalculator.java @@ -8,6 +8,8 @@ import de.embl.schwab.crosshair.utils.GeometryUtils; import net.imglib2.RealPoint; import org.scijava.vecmath.Vector3d; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.FileWriter; import java.io.IOException; @@ -18,6 +20,8 @@ public class AccuracyCalculator { + private static final Logger logger = LoggerFactory.getLogger(AccuracyCalculator.class); + private transient BlockPlane beforeBlock; private transient BlockPlane beforeTarget; private transient Plane afterBlock; @@ -97,7 +101,7 @@ public void saveAccuracy( String jsonPath ) { fileWriter.flush(); fileWriter.close(); } catch (IOException e1) { - e1.printStackTrace(); + logger.error("Error saving accuracy measures", e1); } } diff --git a/src/main/java/de/embl/schwab/crosshair/ui/command/MeasureTargetingAccuracyCommand.java b/src/main/java/de/embl/schwab/crosshair/ui/command/MeasureTargetingAccuracyCommand.java index d8f3499..2a37adb 100644 --- a/src/main/java/de/embl/schwab/crosshair/ui/command/MeasureTargetingAccuracyCommand.java +++ b/src/main/java/de/embl/schwab/crosshair/ui/command/MeasureTargetingAccuracyCommand.java @@ -6,6 +6,8 @@ import org.scijava.command.Command; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; @@ -14,6 +16,8 @@ @Plugin(type = Command.class, menuPath = "Plugins>Crosshair>Analysis>Measure Targeting Accuracy" ) public class MeasureTargetingAccuracyCommand implements Command { + private static final Logger logger = LoggerFactory.getLogger(MeasureTargetingAccuracyCommand.class); + @Parameter(label="Before targeting image xml") public File beforeTargetingXml; @@ -41,7 +45,7 @@ public void run() { new TargetingAccuracy( beforeTargetingXml, registeredAfterTargetingXml, crosshairSettingsJson, crosshairSolutionJson ); } catch (SpimDataException e) { - e.printStackTrace(); + logger.error("Error opening targeting accuracy", e); } } } diff --git a/src/main/java/de/embl/schwab/crosshair/ui/swing/SliderPanelDouble.java b/src/main/java/de/embl/schwab/crosshair/ui/swing/SliderPanelDouble.java index 78f6756..6bb8571 100644 --- a/src/main/java/de/embl/schwab/crosshair/ui/swing/SliderPanelDouble.java +++ b/src/main/java/de/embl/schwab/crosshair/ui/swing/SliderPanelDouble.java @@ -47,6 +47,8 @@ import bdv.util.BoundedValue; import bdv.util.BoundedValueDouble; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A {@link JSlider} with a {@link JSpinner} next to it, both modifying the same @@ -55,6 +57,8 @@ */ public class SliderPanelDouble extends JPanel implements BoundedValueDouble.UpdateListener { + private static final Logger logger = LoggerFactory.getLogger(SliderPanelDouble.class); + private static final long serialVersionUID = 6444334522127424416L; private static final int sliderLength = 10000; @@ -168,7 +172,7 @@ public void commitSpinnerEdits() { try { spinner.commitEdit(); } catch (ParseException e) { - e.printStackTrace(); + logger.error("Error committing spinner edits", e); } } diff --git a/src/main/java/de/embl/schwab/crosshair/utils/Utils.java b/src/main/java/de/embl/schwab/crosshair/utils/Utils.java index efb62e7..f0062c9 100644 --- a/src/main/java/de/embl/schwab/crosshair/utils/Utils.java +++ b/src/main/java/de/embl/schwab/crosshair/utils/Utils.java @@ -4,6 +4,8 @@ import ij3d.Content; import ij3d.Image3DUniverse; import org.scijava.vecmath.Point3d; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.swing.*; import java.awt.*; @@ -12,6 +14,8 @@ public class Utils { + private static final Logger logger = LoggerFactory.getLogger(Utils.class); + public static void printImageMinMax (Content imageContent) { Point3d min = new Point3d(); Point3d max = new Point3d(); @@ -78,7 +82,7 @@ public static void resetCrossPlatformSwingLookAndFeel() { try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() ); } catch (Exception e) { - e.printStackTrace(); + logger.error("Error setting look and feel", e); } } } diff --git a/src/test/java/de/embl/schwab/crosshair/io/STLResourceLoaderTest.java b/src/test/java/de/embl/schwab/crosshair/io/STLResourceLoaderTest.java index 16ac2eb..309d6fd 100644 --- a/src/test/java/de/embl/schwab/crosshair/io/STLResourceLoaderTest.java +++ b/src/test/java/de/embl/schwab/crosshair/io/STLResourceLoaderTest.java @@ -1,9 +1,12 @@ package de.embl.schwab.crosshair.io; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; import customnode.CustomMesh; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.slf4j.LoggerFactory; import java.util.Map; @@ -20,6 +23,10 @@ void loadSTL(String modelName) { @Test void loadInvalidSTL() { + // Disable logging to keep the test logs clean (we're expecting an error here) + Logger logger = (Logger) LoggerFactory.getLogger(STLResourceLoader.class); + logger.setLevel(Level.OFF); + Map currentStl = STLResourceLoader.loadSTL("invalid.stl"); assertNull(currentStl); } diff --git a/src/test/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReaderTest.java b/src/test/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReaderTest.java index fd80d7c..4c98c5b 100644 --- a/src/test/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReaderTest.java +++ b/src/test/java/de/embl/schwab/crosshair/legacy/OldFormatSettingsReaderTest.java @@ -1,8 +1,11 @@ package de.embl.schwab.crosshair.legacy; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.slf4j.LoggerFactory; import java.io.File; import java.nio.file.Path; @@ -32,6 +35,10 @@ void readSettings() { @Test void readInvalidSettings( @TempDir Path tempDir ) { + // Disable logging to keep the test logs clean (we're expecting an error here) + Logger logger = (Logger) LoggerFactory.getLogger(OldFormatSettingsReader.class); + logger.setLevel(Level.OFF); + File invalidJsonPath = tempDir.resolve( "invalid.json" ).toFile(); OldFormatSettings settings = oldFormatSettingsReader.readSettings( invalidJsonPath.getAbsolutePath() ); diff --git a/src/test/java/de/embl/schwab/crosshair/settings/SettingsReaderTest.java b/src/test/java/de/embl/schwab/crosshair/settings/SettingsReaderTest.java index 8976472..b2cbdf0 100644 --- a/src/test/java/de/embl/schwab/crosshair/settings/SettingsReaderTest.java +++ b/src/test/java/de/embl/schwab/crosshair/settings/SettingsReaderTest.java @@ -1,8 +1,11 @@ package de.embl.schwab.crosshair.settings; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.slf4j.LoggerFactory; import java.io.File; import java.nio.file.Path; @@ -39,6 +42,10 @@ void readSettings() { @Test void readInvalidSettings( @TempDir Path tempDir ) { + // Disable logging to keep the test logs clean (we're expecting an error here) + Logger logger = (Logger) LoggerFactory.getLogger(SettingsReader.class); + logger.setLevel(Level.OFF); + File invalidJsonPath = tempDir.resolve( "invalid.json" ).toFile(); Settings settings = settingsReader.readSettings( invalidJsonPath.getAbsolutePath() ); diff --git a/src/test/java/de/embl/schwab/crosshair/solution/SolutionReaderTest.java b/src/test/java/de/embl/schwab/crosshair/solution/SolutionReaderTest.java index 1919163..9264675 100644 --- a/src/test/java/de/embl/schwab/crosshair/solution/SolutionReaderTest.java +++ b/src/test/java/de/embl/schwab/crosshair/solution/SolutionReaderTest.java @@ -4,6 +4,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.slf4j.LoggerFactory; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; import java.io.File; import java.nio.file.Path; @@ -36,6 +39,10 @@ void readSolution() { @Test void readInvalidSolution( @TempDir Path tempDir ) { + // Disable logging to keep the test logs clean (we're expecting an error here) + Logger logger = (Logger) LoggerFactory.getLogger(SolutionReader.class); + logger.setLevel(Level.OFF); + File invalidJsonPath = tempDir.resolve( "invalid.json" ).toFile(); Solution solution = solutionReader.readSolution( invalidJsonPath.getAbsolutePath() );