forked from I2P_Developers/i2p.i2p
use partial match for dups; add config for dups
This commit is contained in:
@@ -58,6 +58,8 @@ public class LogManager {
|
||||
private static final String PROP_LOG_BUFFER_SIZE = "logger.logBufferSize";
|
||||
/** @since 0.9.2 */
|
||||
private static final String PROP_DROP = "logger.dropOnOverflow";
|
||||
/** @since 0.9.3 */
|
||||
private static final String PROP_DUP = "logger.dropDuplicates";
|
||||
public final static String PROP_RECORD_PREFIX = "logger.record.";
|
||||
|
||||
public final static String DEFAULT_FORMAT = DATE + " " + PRIORITY + " [" + THREAD + "] " + CLASS + ": " + MESSAGE;
|
||||
@@ -120,6 +122,7 @@ public class LogManager {
|
||||
private final LogConsoleBuffer _consoleBuffer;
|
||||
private int _logBufferSize = MAX_BUFFER;
|
||||
private boolean _dropOnOverflow;
|
||||
private boolean _dropDuplicates;
|
||||
private final AtomicLong _droppedRecords = new AtomicLong();
|
||||
|
||||
private boolean _alreadyNoticedMissingConfig;
|
||||
@@ -279,6 +282,13 @@ public class LogManager {
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.3
|
||||
*/
|
||||
boolean shouldDropDuplicates() {
|
||||
return _dropDuplicates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not log here, deadlock of LogWriter via rereadConfig().
|
||||
*/
|
||||
@@ -368,7 +378,9 @@ public class LogManager {
|
||||
_logBufferSize = Integer.parseInt(str);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
|
||||
_dropOnOverflow = Boolean.valueOf(config.getProperty(PROP_DROP)).booleanValue();
|
||||
_dropOnOverflow = Boolean.parseBoolean(config.getProperty(PROP_DROP));
|
||||
String str = config.getProperty(PROP_DUP);
|
||||
_dropDuplicates = str == null || Boolean.parseBoolean(str);
|
||||
|
||||
//if (_log.shouldLog(Log.DEBUG))
|
||||
// _log.debug("Log set to use the base log file as " + _baseLogfilename);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
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
|
||||
@@ -62,8 +60,11 @@ class LogRecord {
|
||||
return _throwable;
|
||||
}
|
||||
|
||||
private static final int MATCH_LEN = 40;
|
||||
|
||||
/**
|
||||
* Matches source class, message string, and throwable class only.
|
||||
* Matches source class, first part of message string, and throwable class only.
|
||||
* Used only by LogWriter to eliminate dups.
|
||||
* @since 0.9.3
|
||||
*/
|
||||
@Override
|
||||
@@ -72,7 +73,10 @@ class LogRecord {
|
||||
return false;
|
||||
LogRecord r = (LogRecord) o;
|
||||
return _source == r._source &&
|
||||
DataHelper.eq(_message, r._message) &&
|
||||
((_message == null && r._message == null) ||
|
||||
(_message != null && r._message != null &&
|
||||
((_message.length() <= MATCH_LEN) ? _message.equals(r._message)
|
||||
: _message.regionMatches(0, r._message, 0, MATCH_LEN)))) &&
|
||||
((_throwable == null && r._throwable == null) ||
|
||||
(_throwable != null && r._throwable != null && _throwable.getClass() == r._throwable.getClass()));
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class LogWriter implements Runnable {
|
||||
LogRecord rec;
|
||||
int dupCount = 0;
|
||||
while ((rec = records.poll()) != null) {
|
||||
if (rec.equals(last)) {
|
||||
if (_manager.shouldDropDuplicates() && rec.equals(last)) {
|
||||
dupCount++;
|
||||
} else {
|
||||
if (dupCount > 0) {
|
||||
|
||||
Reference in New Issue
Block a user