I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3c95f0b6 authored by zzz's avatar zzz
Browse files

* LogWriter: Duplicate log message removal

parent 33477887
No related branches found
No related tags found
No related merge requests found
package net.i2p.util; package net.i2p.util;
import net.i2p.data.DataHelper;
/* /*
* free (adj.): unencumbered; not under the control of others * free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain * Written by jrandom in 2003 and released into the public domain
...@@ -59,4 +61,19 @@ class LogRecord { ...@@ -59,4 +61,19 @@ class LogRecord {
public Throwable getThrowable() { public Throwable getThrowable() {
return _throwable; 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 { ...@@ -26,8 +26,8 @@ class LogWriter implements Runnable {
/** every 10 seconds? why? Just have the gui force a reread after a change?? */ /** 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 CONFIG_READ_INTERVAL = 50 * 1000;
private final static long FLUSH_INTERVAL = 9 * 1000; private final static long FLUSH_INTERVAL = 9 * 1000;
private long _lastReadConfig = 0; private long _lastReadConfig;
private long _numBytesInCurrentFile = 0; private long _numBytesInCurrentFile;
// volatile as it changes on log file rotation // volatile as it changes on log file rotation
private volatile Writer _currentOut; private volatile Writer _currentOut;
private int _rotationNum = -1; private int _rotationNum = -1;
...@@ -66,16 +66,35 @@ class LogWriter implements Runnable { ...@@ -66,16 +66,35 @@ class LogWriter implements Runnable {
} }
public void flushRecords() { flushRecords(true); } public void flushRecords() { flushRecords(true); }
public void flushRecords(boolean shouldWait) { public void flushRecords(boolean shouldWait) {
try { try {
// zero copy, drain the manager queue directly // zero copy, drain the manager queue directly
Queue<LogRecord> records = _manager.getQueue(); Queue<LogRecord> records = _manager.getQueue();
if (records == null) return; if (records == null) return;
if (!records.isEmpty()) { if (!records.isEmpty()) {
LogRecord last = null;
LogRecord rec; LogRecord rec;
int dupCount = 0;
while ((rec = records.poll()) != null) { 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 { try {
if (_currentOut != null) if (_currentOut != null)
_currentOut.flush(); _currentOut.flush();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment