This is an automated email from the ASF dual-hosted git repository.
snagel pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nutch.git
The following commit(s) were added to refs/heads/master by this push:
new 0624d25 NUTCH-2701 Fetcher: log dates and times also in
human-readable form - add human-readable date to log message about time limit -
move date formatter to TimingUtil - use new thread-safe date and time API
new bf75e96 Merge pull request #447 from
sebastian-nagel/NUTCH-2701-fetcher-log-times-human-readable
0624d25 is described below
commit 0624d2588ee3b2e84be28ffb59db6d62c1456752
Author: Sebastian Nagel <[email protected]>
AuthorDate: Fri Mar 22 14:21:11 2019 +0100
NUTCH-2701 Fetcher: log dates and times also in human-readable form
- add human-readable date to log message about time limit
- move date formatter to TimingUtil
- use new thread-safe date and time API
---
src/java/org/apache/nutch/fetcher/Fetcher.java | 11 +++++------
src/java/org/apache/nutch/util/TimingUtil.java | 16 ++++++++++++++++
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java
b/src/java/org/apache/nutch/fetcher/Fetcher.java
index fe9e71e..792ee49 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -19,7 +19,6 @@ package org.apache.nutch.fetcher;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -427,10 +426,9 @@ public class Fetcher extends NutchTool implements Tool {
checkConfiguration();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long start = System.currentTimeMillis();
if (LOG.isInfoEnabled()) {
- LOG.info("Fetcher: starting at {}", sdf.format(start));
+ LOG.info("Fetcher: starting at {}", TimingUtil.logDateMillis(start));
LOG.info("Fetcher: segment: {}", segment);
}
@@ -440,7 +438,8 @@ public class Fetcher extends NutchTool implements Tool {
long timelimit = getConf().getLong("fetcher.timelimit.mins", -1);
if (timelimit != -1) {
timelimit = System.currentTimeMillis() + (timelimit * 60 * 1000);
- LOG.info("Fetcher Timelimit set for : {}", timelimit);
+ LOG.info("Fetcher Timelimit set for : {} ({})", timelimit,
+ TimingUtil.logDateMillis(timelimit));
getConf().setLong("fetcher.timelimit", timelimit);
}
@@ -507,8 +506,8 @@ public class Fetcher extends NutchTool implements Tool {
}
long end = System.currentTimeMillis();
- LOG.info("Fetcher: finished at {}, elapsed: {}", sdf.format(end),
- TimingUtil.elapsedTime(start, end));
+ LOG.info("Fetcher: finished at {}, elapsed: {}",
+ TimingUtil.logDateMillis(end), TimingUtil.elapsedTime(start, end));
}
/** Run the fetcher. */
diff --git a/src/java/org/apache/nutch/util/TimingUtil.java
b/src/java/org/apache/nutch/util/TimingUtil.java
index 29520c1..3f3e74e 100644
--- a/src/java/org/apache/nutch/util/TimingUtil.java
+++ b/src/java/org/apache/nutch/util/TimingUtil.java
@@ -16,10 +16,26 @@
*/
package org.apache.nutch.util;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;
public class TimingUtil {
+ /** Formats dates for logging */
+ public static DateTimeFormatter logDateFormat =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+ /**
+ * Convert epoch milliseconds ({@link System#currentTimeMillis()}) into date
+ * string (local time zone) used for logging
+ */
+ public static String logDateMillis(long millis) {
+ return logDateFormat.format(
+ LocalDateTime.ofInstant(Instant.ofEpochMilli(millis),
ZoneId.systemDefault()));
+ }
+
/**
* Calculate the elapsed time between two times specified in milliseconds.
*