diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java index 96d6ad6e17fe13ce35cd22be1b72824a8928d4f0..689b046f92832a1aad85c7b7b90e87061e4489c8 100644 --- a/core/java/src/net/i2p/util/LogManager.java +++ b/core/java/src/net/i2p/util/LogManager.java @@ -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); diff --git a/core/java/src/net/i2p/util/LogRecord.java b/core/java/src/net/i2p/util/LogRecord.java index b1bd6b8d4483f5863530dbf73f4dcdb60b4db9a6..cf6b34728f7c617d1a6bef7d1c0267f7a7828918 100644 --- a/core/java/src/net/i2p/util/LogRecord.java +++ b/core/java/src/net/i2p/util/LogRecord.java @@ -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())); } diff --git a/core/java/src/net/i2p/util/LogWriter.java b/core/java/src/net/i2p/util/LogWriter.java index a26433bb8afc4d22b63e1627ff760f15ed144ee8..12706ba4c0b6f9af8cc0ce493c1402e3dee526f7 100644 --- a/core/java/src/net/i2p/util/LogWriter.java +++ b/core/java/src/net/i2p/util/LogWriter.java @@ -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) {