forked from I2P_Developers/i2p.i2p
* LogWriter: Duplicate log message removal
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package net.i2p.util;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
@@ -59,4 +61,19 @@ class LogRecord {
|
||||
public Throwable getThrowable() {
|
||||
return _throwable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches source class, message string, and throwable class only.
|
||||
* @since 0.9.3
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof LogRecord))
|
||||
return false;
|
||||
LogRecord r = (LogRecord) o;
|
||||
return _source == r._source &&
|
||||
DataHelper.eq(_message, r._message) &&
|
||||
((_throwable == null && r._throwable == null) ||
|
||||
(_throwable != null && r._throwable != null && _throwable.getClass() == r._throwable.getClass()));
|
||||
}
|
||||
}
|
||||
|
@@ -26,8 +26,8 @@ class LogWriter implements Runnable {
|
||||
/** every 10 seconds? why? Just have the gui force a reread after a change?? */
|
||||
private final static long CONFIG_READ_INTERVAL = 50 * 1000;
|
||||
private final static long FLUSH_INTERVAL = 9 * 1000;
|
||||
private long _lastReadConfig = 0;
|
||||
private long _numBytesInCurrentFile = 0;
|
||||
private long _lastReadConfig;
|
||||
private long _numBytesInCurrentFile;
|
||||
// volatile as it changes on log file rotation
|
||||
private volatile Writer _currentOut;
|
||||
private int _rotationNum = -1;
|
||||
@@ -66,16 +66,35 @@ class LogWriter implements Runnable {
|
||||
}
|
||||
|
||||
public void flushRecords() { flushRecords(true); }
|
||||
|
||||
public void flushRecords(boolean shouldWait) {
|
||||
try {
|
||||
// zero copy, drain the manager queue directly
|
||||
Queue<LogRecord> records = _manager.getQueue();
|
||||
if (records == null) return;
|
||||
if (!records.isEmpty()) {
|
||||
LogRecord last = null;
|
||||
LogRecord rec;
|
||||
int dupCount = 0;
|
||||
while ((rec = records.poll()) != null) {
|
||||
writeRecord(rec);
|
||||
if (rec.equals(last)) {
|
||||
dupCount++;
|
||||
} else {
|
||||
if (dupCount > 0) {
|
||||
if (dupCount == 1)
|
||||
writeRecord("*** 1 similar message omitted\n");
|
||||
else
|
||||
writeRecord("*** " + dupCount + " similar messages omitted\n");
|
||||
dupCount = 0;
|
||||
}
|
||||
last = rec;
|
||||
writeRecord(rec);
|
||||
}
|
||||
}
|
||||
if (dupCount == 1)
|
||||
writeRecord("*** 1 similar message omitted\n");
|
||||
else if (dupCount > 0)
|
||||
writeRecord("*** " + dupCount + " similar messages omitted\n");
|
||||
try {
|
||||
if (_currentOut != null)
|
||||
_currentOut.flush();
|
||||
|
Reference in New Issue
Block a user