Skip to content
Snippets Groups Projects
Commit b899f6c6 authored by Georg Graßnick's avatar Georg Graßnick :thinking:
Browse files

Add logging functionality

parent 80e6799b
No related branches found
No related tags found
1 merge request!5Add logging functionality
......@@ -29,6 +29,10 @@ repositories {
dependencies {
// Use JUnit test framework
testImplementation('org.junit.jupiter:junit-jupiter:5.4.2')
// Logging
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
}
test {
......
package de.tudresden.inf.mci.brailleplot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ConcurrentLinkedDeque;
/**
......@@ -23,11 +26,14 @@ public final class App {
private static final int EXIT_SUCCESS = 0;
private static final int EXIT_ERROR = 1;
private final Logger mLogger;
private ConcurrentLinkedDeque<Runnable> mFinalizers;
private App() {
sInstance = this;
mFinalizers = new ConcurrentLinkedDeque<>();
mLogger = LoggerFactory.getLogger(this.getClass());
}
/**
......@@ -75,9 +81,9 @@ public final class App {
*/
public static void terminateWithException(final Exception e, final String message) {
if (!message.isEmpty()) {
System.err.println(message);
getInstance().mLogger.error(message);
}
e.printStackTrace();
getInstance().mLogger.error("Application will now shut down due to an unrecoverable error", e);
getInstance().runFinalizers();
System.exit(EXIT_ERROR);
}
......@@ -89,11 +95,15 @@ public final class App {
*/
int run(final String[] args) {
// Has to be the first finalizer to be added, so that it is run last
registerFinalizer(() -> {
System.out.println("Application terminated.");
mLogger.info("Application terminated");
});
try {
// Logging example
mLogger.info("Application started");
// Parse command line parameters
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment