Add tinylog logging

Change-Id: I530b4e7e3119444070cff2a25cc1450d33d8f563
diff --git a/Changes b/Changes
index 7479668..cd9bc03 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 0.2.4 2021-04-27
     - Fix temporary session-riding capabilities.
+    - Introduced central tinylog.
 
 0.2.3 2021-03-24
     - Added trail info to RTF export.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f0da782..3d91f19 100644
--- a/pom.xml
+++ b/pom.xml
@@ -109,6 +109,18 @@
       <artifactId>commons-io</artifactId>
       <version>2.8.0</version>
     </dependency>
+
+    <!-- Logging -->
+    <dependency>
+      <groupId>org.tinylog</groupId>
+      <artifactId>tinylog-impl</artifactId>
+      <version>2.4.0-M1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.tinylog</groupId>
+      <artifactId>tinylog-api</artifactId>
+      <version>2.4.0-M1</version>
+    </dependency>
     
   </dependencies>
   
diff --git a/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java b/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
index 8382254..8313810 100644
--- a/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
+++ b/src/main/java/de/ids_mannheim/korap/plkexport/ExWSConf.java
@@ -13,6 +13,8 @@
 import java.util.Properties;
 import java.nio.charset.StandardCharsets;
 
+import org.tinylog.Logger;
+
 public class ExWSConf {
 
     // Version of Export Plugin
@@ -48,7 +50,7 @@
                     .getResourceAsStream(propFile);
 
                 if (iFile == null) {
-                    System.err.println("Unable to load properties.");
+                    Logger.error("Unable to load properties.");
                     return null;
                 };
 
@@ -57,7 +59,7 @@
                 iFile.close();
             }
             catch (IOException e) {
-                System.err.println(e.getLocalizedMessage());
+                Logger.error(e);
                 return null;
             };
         };
diff --git a/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java b/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
index a0d2c83..1560e5b 100644
--- a/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
+++ b/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
@@ -14,6 +14,8 @@
 
 import org.glassfish.jersey.servlet.ServletContainer;
 
+import org.tinylog.Logger;
+
 /**
  * Server to provide the export web service
  */
@@ -57,8 +59,8 @@
 
         try {
             jettyServer.start();
-            System.out.println("PluginServer available under: http://" + host+ ":" + portStr);
-            System.out.println(
+            Logger.info("PluginServer available under: http://" + host+ ":" + portStr);
+            Logger.info(
                 "ApiServer expected under: " +
                 properties.getProperty("api.scheme") +
                 "://" +
diff --git a/src/main/java/de/ids_mannheim/korap/plkexport/Service.java b/src/main/java/de/ids_mannheim/korap/plkexport/Service.java
index cbe88db..e69eb3c 100644
--- a/src/main/java/de/ids_mannheim/korap/plkexport/Service.java
+++ b/src/main/java/de/ids_mannheim/korap/plkexport/Service.java
@@ -42,6 +42,8 @@
 
 import static org.apache.commons.io.FilenameUtils.getExtension;
 
+import org.tinylog.Logger;
+
 import org.glassfish.jersey.media.sse.EventOutput;
 import org.glassfish.jersey.media.sse.OutboundEvent;
 import org.glassfish.jersey.media.sse.SseFeature;
@@ -69,7 +71,6 @@
  * - Do not expect all meta data per match.
  * - Upgrade default pageSize to 50.
  * - Add loading marker.
- * - Use a central logging mechanism.
  * - Add infos to JsonExporter.
  *   - e.g. q &amp; cq string representation.
  * - Check pageSize after init (so pageSize is not
@@ -123,13 +124,13 @@
     
     private final static Base64.Decoder b64Dec = Base64.getDecoder();
 
+    
     @Context
     private HttpServletRequest servletReq;
 
     @Context
     private ContainerRequest req;
 
-
     /*
      * Private method to run the export,
      * either static or streaming
@@ -270,6 +271,7 @@
         }
 
         catch (Exception e) {
+            Logger.error(e);
             throw new WebApplicationException(
                 responseForm(
                     Status.INTERNAL_SERVER_ERROR,
@@ -300,6 +302,7 @@
             }
 
             catch (Exception e) {
+                Logger.error(e);
                 throw new WebApplicationException(
                     responseForm(
                         Status.INTERNAL_SERVER_ERROR,
@@ -340,6 +343,7 @@
         }
 
         catch (Exception e) {
+            Logger.error(e);
             throw new WebApplicationException(
                 responseForm(
                     Status.INTERNAL_SERVER_ERROR,
@@ -473,6 +477,7 @@
                         }
 
                         catch (IOException ioe) {
+                            Logger.error(ioe);
                             throw new RuntimeException(
                                 "Error when writing event output.", ioe
                                 );
@@ -491,6 +496,7 @@
                         }
 
                         catch (IOException ioClose) {
+                            Logger.error(ioClose);
                             throw new RuntimeException(
                                 "Error when closing the event output.", ioClose
                                 );
@@ -702,6 +708,7 @@
             templateData.put("dict", this.getDictionary());
 
         } catch (Exception e) {
+            Logger.error(e);
             return Response
                 .ok(new String("Dictionary not found"))
                 .status(Status.INTERNAL_SERVER_ERROR)
@@ -716,6 +723,7 @@
 
         // Unable to find template
         catch (Exception e) {
+            Logger.error(e);
             return Response
                 .ok(new String("Template not found"))
                 .status(Status.INTERNAL_SERVER_ERROR)
diff --git a/src/main/resources/tinylog.properties b/src/main/resources/tinylog.properties
new file mode 100644
index 0000000..565f707
--- /dev/null
+++ b/src/main/resources/tinylog.properties
@@ -0,0 +1,2 @@
+writer        = console
+writer.format = {date: yyyy-MM-dd HH:mm:ss.SSS}:{level}: {message} at {file}:{line}
\ No newline at end of file