totalngrams: add console logger for > WARNING levels
diff --git a/src/main/java/org/ids_mannheim/TotalNGram.java b/src/main/java/org/ids_mannheim/TotalNGram.java
index 82a8f56..7eadabd 100644
--- a/src/main/java/org/ids_mannheim/TotalNGram.java
+++ b/src/main/java/org/ids_mannheim/TotalNGram.java
@@ -12,9 +12,7 @@
import java.util.Locale;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.FileHandler;
-import java.util.logging.Logger;
-import java.util.logging.SimpleFormatter;
+import java.util.logging.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -100,6 +98,9 @@
//java.util.logging.SimpleFormatter.format="%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%n";
java.util.Locale.setDefault(Locale.Category.FORMAT, Locale.ROOT);
logger.addHandler(fileHandler);
+ ConsoleHandler consoleHandler = new ConsoleHandler();
+ consoleHandler.setLevel(Level.WARNING);
+ logger.addHandler(consoleHandler);
} catch (Exception e) {
System.err.println("Cannot write logfile " + logFileName + ": " + e);
System.exit(-1);
diff --git a/src/main/java/org/ids_mannheim/Worker.java b/src/main/java/org/ids_mannheim/Worker.java
index ff855d4..238e004 100644
--- a/src/main/java/org/ids_mannheim/Worker.java
+++ b/src/main/java/org/ids_mannheim/Worker.java
@@ -102,7 +102,7 @@
}
pool.markFree(poolIndex);
if (texts > 0) {
- logger.info(pool.getHost(poolIndex)+" finished " + fname + " with "+texts+ " texts");
+ logger.info(pool.getHost(poolIndex) + " finished " + fname + " with " + texts + " texts");
etaPrinter.update(file_size);
retries = MAX_RETRIES;
index = queue.take();
@@ -111,7 +111,7 @@
logger.warning("Retrying " + fname);
sleep(1000);
} else {
- logger.severe ("Giving up " + fname);
+ logger.severe("Giving up " + fname);
index = queue.take();
}
}
diff --git a/src/main/java/org/ids_mannheim/WorkerNodePool.java b/src/main/java/org/ids_mannheim/WorkerNodePool.java
index 3d9485e..a175926 100644
--- a/src/main/java/org/ids_mannheim/WorkerNodePool.java
+++ b/src/main/java/org/ids_mannheim/WorkerNodePool.java
@@ -1,8 +1,6 @@
package org.ids_mannheim;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.IntStream;
@@ -43,6 +41,7 @@
return i;
} else {
TotalNGram.logger.warning("No free worker node. This should not happen.");
+ //noinspection BusyWait
Thread.sleep(1000);
}
}
@@ -57,11 +56,11 @@
procs = 1;
host = single[0];
} else if (single.length == 2) {
- procs = Integer.valueOf(single[0]);
+ procs = Integer.parseInt(single[0]);
host = single[1];
} else {
host = "";
- System.err.println("ERROR: Wrong worker node format: " + s);
+ TotalNGram.logger.severe("Wrong worker node format: " + s);
System.exit(-1);
}
IntStream.range(0, procs).forEach(u -> {
diff --git a/src/main/resources/logging.properties b/src/main/resources/logging.properties
index ce9250c..65f981e 100644
--- a/src/main/resources/logging.properties
+++ b/src/main/resources/logging.properties
@@ -1,4 +1,4 @@
-handlers= java.util.logging.FileHandler
+handlers= java.util.logging.ConsoleHandler java.util.logging.FileHandler
.level= INFO
java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s] %5$s %n
java.util.logging.FileHandler.level = INFO
@@ -9,5 +9,5 @@
# java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n
# java.util.logging.SimpleFormatter.format="%1$tb %1$td, %1$tY %1$tH:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%n"
-java.util.logging.ConsoleHandler.level = WARNING
+java.util.logging.ConsoleHandler.level = SEVERE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter