Skip to content

Commit

Permalink
add logback logging
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Meech committed Jul 16, 2024
1 parent 330c7f4 commit e08e062
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 15 deletions.
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@
<artifactId>imagej-utils</artifactId>
<version>${imagej-utils.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/de/embl/schwab/crosshair/io/STLResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, CustomMesh> meshes;
private ArrayList<Point3f> vertices = new ArrayList();
private String name = null;
Expand All @@ -35,7 +39,7 @@ public static Map<String, CustomMesh> loadSTL(String name) {
try {
return STLResourceLoader.load(name);
} catch (Exception var2) {
var2.printStackTrace();
logger.error("Error loading STL file", var2);
return null;
}
}
Expand All @@ -52,7 +56,7 @@ public static Map<String, CustomMesh> 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;
}

Expand Down Expand Up @@ -101,8 +105,7 @@ private void parseBinary() {

inputStream.close();
} catch (IOException var10) {
var10.printStackTrace();

logger.error("Error parsing binary", var10);
}

CustomMesh cm = this.createCustomMesh();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +13,8 @@
*/
public class OldFormatSettingsReader {

private static final Logger logger = LoggerFactory.getLogger(OldFormatSettingsReader.class);

/**
* Create a settings reader
*/
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +22,8 @@

public class SettingsReader {

private static final Logger logger = LoggerFactory.getLogger(SettingsReader.class);

public SettingsReader() {}

public Settings readSettings(String filePath ) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +15,8 @@

public class SettingsWriter {

private static final Logger logger = LoggerFactory.getLogger(SettingsWriter.class);

public SettingsWriter() { }

public Settings createSettings(PlaneManager planeManager, Map<String, Content> imageNameToContent ) {
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,7 +32,7 @@ public void writeSolution() {
fileWriter.flush();
fileWriter.close();
} catch (IOException e1) {
e1.printStackTrace();
logger.error("Error writing solution", e1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -168,7 +172,7 @@ public void commitSpinnerEdits() {
try {
spinner.commitEdit();
} catch (ParseException e) {
e.printStackTrace();
logger.error("Error committing spinner edits", e);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/de/embl/schwab/crosshair/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<String, CustomMesh> currentStl = STLResourceLoader.loadSTL("invalid.stl");
assertNull(currentStl);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() );

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() );

Expand Down

0 comments on commit e08e062

Please sign in to comment.