summaryrefslogtreecommitdiffstats
path: root/container-accesslogging
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-12 11:03:49 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2016-09-12 11:03:49 +0200
commita3996baf85fc0a07281a39e4e66e89879cd92bac (patch)
tree5cdeea41b9f810396efb628b1b05ae326daabb4f /container-accesslogging
parent25927a2ee43ea4c07bcd32df8de6b63466bd874c (diff)
If there is nothing to do we will flush every 100ms, if not we will be a bit more relaxed.
Diffstat (limited to 'container-accesslogging')
-rw-r--r--container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java20
1 files changed, 13 insertions, 7 deletions
diff --git a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java
index 33dd29ba2b7..7ff6fba5999 100644
--- a/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java
+++ b/container-accesslogging/src/main/java/com/yahoo/container/logging/LogFileHandler.java
@@ -44,6 +44,7 @@ public class LogFileHandler extends StreamHandler {
static private class LogThread extends Thread {
LogFileHandler logFileHandler;
+ long lastFlush = 0;
public LogThread(LogFileHandler logFile) {
super("Logger");
setDaemon(true);
@@ -62,22 +63,27 @@ public class LogFileHandler extends StreamHandler {
}
private void storeLogRecords() throws InterruptedException {
- long lastFlush = 0;
while (!isInterrupted()) {
LogRecord r = logFileHandler.logQueue.poll(100, TimeUnit.MILLISECONDS);
- long now = System.nanoTime();
if (r != null) {
if (r == logFileHandler.rotateCmd) {
logFileHandler.internalRotateNow();
- lastFlush = now;
+ lastFlush = System.nanoTime();
} else {
logFileHandler.internalPublish(r);
}
+ flushIfOld(3, TimeUnit.SECONDS);
+ } else {
+ flushIfOld(100, TimeUnit.MILLISECONDS);
}
- if (TimeUnit.NANOSECONDS.toSeconds(now - lastFlush) > 5) {
- logFileHandler.flush();
- lastFlush = now;
- }
+ }
+ }
+
+ private void flushIfOld(long age, TimeUnit unit) {
+ long now = System.nanoTime();
+ if (TimeUnit.NANOSECONDS.toMillis(now - lastFlush) > unit.toMillis(age)) {
+ logFileHandler.flush();
+ lastFlush = now;
}
}
}