-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from phyloref/replace-stderr-with-log4j
This PR replaces most of our System.err calls with calls to the SLF4J logging system. This will make it easier to add debugging information in the future, when we can use verbose flags (`-v`, `-vv`) to provide increasingly detailed debugging information (#31). Closes #51.
- Loading branch information
Showing
6 changed files
with
47 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
import org.semanticweb.owlapi.reasoner.OWLReasoner; | ||
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; | ||
import org.semanticweb.owlapi.util.AutoIRIMapper; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Resolve an ontology of phyloreferences provided on the command line, and report on the resolution | ||
|
@@ -38,6 +40,9 @@ | |
* @author Gaurav Vaidya <[email protected]> | ||
*/ | ||
public class ResolveCommand implements Command { | ||
/** Set up a logger to use for providing logging. */ | ||
private static final Logger logger = LoggerFactory.getLogger(ResolveCommand.class); | ||
|
||
/** | ||
* This command is named "resolve". It should be invoked as "java -jar jphyloref.jar resolve ..." | ||
*/ | ||
|
@@ -115,21 +120,21 @@ public int execute(CommandLine cmdLine) throws RuntimeException { | |
try { | ||
inputStreamToReadFrom = new FileInputStream(inputFilename); | ||
} catch (FileNotFoundException ex) { | ||
System.err.println("Could not open input file '" + inputFilename + "': " + ex); | ||
logger.error("Could not open input file '{}': {}", inputFilename, ex); | ||
return 1; | ||
} | ||
} | ||
|
||
// Report the name of the file being tested. | ||
System.err.println("Input: " + inputFilename); | ||
logger.info("Input: {}", inputFilename); | ||
|
||
// Set up an OWL Ontology Manager to work with. | ||
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
|
||
// Is purl.obolibrary.org down? No worries, you can access local copies | ||
// of your ontologies in the 'ontologies/' folder. | ||
AutoIRIMapper mapper = new AutoIRIMapper(new File("ontologies"), true); | ||
System.err.println("Found local ontologies: " + mapper.getOntologyIRIs()); | ||
logger.info("Found local ontologies: {}", mapper.getOntologyIRIs()); | ||
manager.addIRIMapper(mapper); | ||
|
||
// Is this a JSON or JSON-LD file? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ | |
import org.semanticweb.owlapi.search.EntitySearcher; | ||
import org.semanticweb.owlapi.util.AutoIRIMapper; | ||
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.tap4j.model.Comment; | ||
import org.tap4j.model.Directive; | ||
import org.tap4j.model.Plan; | ||
|
@@ -54,6 +56,9 @@ | |
* @author Gaurav Vaidya <[email protected]> | ||
*/ | ||
public class TestCommand implements Command { | ||
/** Set up a logger to use for providing logging. */ | ||
private static final Logger logger = LoggerFactory.getLogger(TestCommand.class); | ||
|
||
/** This command is named "test". It should be invoked as "java -jar jphyloref.jar test ..." */ | ||
@Override | ||
public String getName() { | ||
|
@@ -119,21 +124,21 @@ public int execute(CommandLine cmdLine) throws RuntimeException { | |
try { | ||
inputStreamToReadFrom = new FileInputStream(inputFilename); | ||
} catch (FileNotFoundException ex) { | ||
System.err.println("Could not open input file '" + inputFilename + "': " + ex); | ||
logger.error("Could not open input file '{}': {}", inputFilename, ex); | ||
return 1; | ||
} | ||
} | ||
|
||
// Report the name of the file being tested. | ||
System.err.println("Input: " + inputFilename); | ||
logger.info("Input: {}", inputFilename); | ||
|
||
// Set up an OWL Ontology Manager to work with. | ||
OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); | ||
|
||
// Is purl.obolibrary.org down? No worries, you can access local copies | ||
// of your ontologies in the 'ontologies/' folder. | ||
AutoIRIMapper mapper = new AutoIRIMapper(new File("ontologies"), true); | ||
System.err.println("Found local ontologies: " + mapper.getOntologyIRIs()); | ||
logger.info("Found local ontologies: {}", mapper.getOntologyIRIs()); | ||
manager.addIRIMapper(mapper); | ||
|
||
// Is this a JSON or JSON-LD file? | ||
|
@@ -157,15 +162,15 @@ public int execute(CommandLine cmdLine) throws RuntimeException { | |
ontology = manager.loadOntologyFromOntologyDocument(inputStreamToReadFrom); | ||
} | ||
} catch (OWLOntologyCreationException ex) { | ||
System.err.println("Could not create ontology '" + inputFilename + "': " + ex); | ||
logger.error("Could not create ontology '{}': {}", inputFilename, ex); | ||
return 1; | ||
} catch (IOException ex) { | ||
System.err.println("Could not read and load ontology '" + inputFilename + "': " + ex); | ||
logger.error("Could not read and load ontology '{}': {}", inputFilename, ex); | ||
return 1; | ||
} | ||
|
||
// Ontology loaded. | ||
System.err.println("Loaded ontology: " + ontology); | ||
logger.info("Loaded ontology: {}", ontology); | ||
|
||
// Reason over the loaded ontology -- but only if the user wants that! | ||
// Set up an OWLReasoner to work with. | ||
|
@@ -175,7 +180,7 @@ public int execute(CommandLine cmdLine) throws RuntimeException { | |
|
||
// Get a list of all phyloreferences. | ||
Set<OWLClass> phylorefs = PhylorefHelper.getPhyloreferences(ontology, reasoner); | ||
System.err.println("Phyloreferences identified: " + phylorefs); | ||
logger.info("Phyloreferences identified: {}", phylorefs); | ||
|
||
// Okay, time to start testing! Each phyloreference counts as one test. | ||
// TAP (https://testanything.org/) can be read by downstream software | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ | |
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; | ||
import org.semanticweb.owlapi.util.AutoIRIMapper; | ||
import org.semanticweb.owlapi.util.VersionInfo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Sets up a webserver that allows reasoning over phyloreferences over HTTP. | ||
|
@@ -50,6 +52,9 @@ | |
* @author Gaurav Vaidya <[email protected]> | ||
*/ | ||
public class WebserverCommand implements Command { | ||
/** Set up a logger to use for providing logging. */ | ||
private static final Logger logger = LoggerFactory.getLogger(WebserverCommand.class); | ||
|
||
/** | ||
* This command is named "webserver". It should be invoked as "java -jar jphyloref.jar webserver | ||
* ..." | ||
|
@@ -97,7 +102,7 @@ public int execute(CommandLine cmdLine) throws RuntimeException { | |
Webserver webserver = new Webserver(this, hostname, port, cmdLine); | ||
while (webserver.isAlive()) {} | ||
} catch (IOException ex) { | ||
System.err.println("An error occurred while running webserver: " + ex); | ||
logger.error("An error occurred while running webserver: {}", ex.toString()); | ||
} | ||
|
||
return 0; | ||
|
@@ -128,15 +133,12 @@ public Webserver(WebserverCommand cmd, String hostname, int port, CommandLine cm | |
this.cmdLine = cmdLine; | ||
|
||
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false); | ||
System.out.println( | ||
"Webserver started with reasoner " | ||
+ ReasonerHelper.getReasonerNameAndVersion( | ||
ReasonerHelper.getReasonerFactoryFromCmdLine(cmdLine)) | ||
+ ". Try accessing it at http://" | ||
+ hostname | ||
+ ":" | ||
+ port | ||
+ "/"); | ||
logger.info( | ||
"Webserver started with reasoner {}. Try accessing it at http://{}:{}/", | ||
ReasonerHelper.getReasonerNameAndVersion( | ||
ReasonerHelper.getReasonerFactoryFromCmdLine(cmdLine)), | ||
hostname, | ||
port); | ||
} | ||
|
||
/** Respond to a request for reasoning over a JSON-LD file (/reason). */ | ||
|
@@ -150,7 +152,7 @@ public JSONObject serveReason(File jsonldFile) | |
// Is purl.obolibrary.org down? No worries, you can access local copies | ||
// of your ontologies in the 'ontologies/' folder. | ||
AutoIRIMapper mapper = new AutoIRIMapper(new File("ontologies"), true); | ||
System.err.println("Found local ontologies: " + mapper.getOntologyIRIs()); | ||
logger.info("Found local ontologies: {}", mapper.getOntologyIRIs()); | ||
manager.addIRIMapper(mapper); | ||
|
||
// Setup ready; parse the file! | ||
|
@@ -204,7 +206,7 @@ public JSONObject serveReason(File jsonldFile) | |
reasoner.dispose(); | ||
|
||
// Log reasoning results. | ||
System.err.println("Phyloreferencing reasoning results: " + nodesPerPhylorefAsString); | ||
logger.info("Phyloreferencing reasoning results: {}", nodesPerPhylorefAsString); | ||
|
||
// Record phyloreferences and matching nodes in JSON response. | ||
response.put("phylorefs", nodesPerPhylorefAsString); | ||
|
@@ -267,7 +269,7 @@ public Response serve(IHTTPSession session) { | |
String path = session.getUri(); | ||
Map<String, List<String>> params = session.getParameters(); | ||
|
||
System.out.println(">> Request received to '" + path + "': " + params); | ||
logger.info(">> Request received to '{}': {}", path, params); | ||
|
||
if (path.equals("/reason")) { | ||
// If it is an OPTIONS request, it's probably someone wanting a | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters