From de27cb1a4666c995c85fa02226d63a3e8532b998 Mon Sep 17 00:00:00 2001 From: zzz <zzz@i2pmail.org> Date: Wed, 16 Mar 2022 07:22:00 -0400 Subject: [PATCH] Util: Increase min log file size limit Rotate the log before we hit the limit, not after --- core/java/src/net/i2p/util/FileLogWriter.java | 2 +- core/java/src/net/i2p/util/LogManager.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/java/src/net/i2p/util/FileLogWriter.java b/core/java/src/net/i2p/util/FileLogWriter.java index 3b3df88c17..5ec7512b0d 100644 --- a/core/java/src/net/i2p/util/FileLogWriter.java +++ b/core/java/src/net/i2p/util/FileLogWriter.java @@ -71,7 +71,7 @@ class FileLogWriter extends LogWriter { System.err.println("Error writing log, disk full? " + t); //t.printStackTrace(); } - if (_numBytesInCurrentFile >= _manager.getFileSize()) { + if (_numBytesInCurrentFile >= _manager.getFileSize() - 1024) { rotateFile(); } } diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java index 1f453995e4..b98f1c5285 100644 --- a/core/java/src/net/i2p/util/LogManager.java +++ b/core/java/src/net/i2p/util/LogManager.java @@ -78,6 +78,7 @@ public class LogManager implements Flushable { public final static String DEFAULT_ROTATIONLIMIT = "2"; public final static String DEFAULT_DEFAULTLEVEL = Log.STR_ERROR; public final static String DEFAULT_ONSCREENLEVEL = Log.STR_CRIT; + private static final int MIN_FILESIZE_LIMIT = 16*1024; private final I2PAppContext _context; private final Log _log; @@ -410,7 +411,7 @@ public class LogManager implements Flushable { else setBaseLogfilename(filename); - _fileSize = getFileSize(config.getProperty(PROP_FILESIZE, DEFAULT_FILESIZE)); + _fileSize = Math.max(MIN_FILESIZE_LIMIT, getFileSize(config.getProperty(PROP_FILESIZE, DEFAULT_FILESIZE))); _rotationLimit = -1; try { @@ -536,7 +537,7 @@ public class LogManager implements Flushable { */ public void setFileSize(int numBytes) { if (numBytes > 0) - _fileSize = numBytes; + _fileSize = Math.max(MIN_FILESIZE_LIMIT, numBytes); } public String getDefaultLimit() { return Log.toLevelString(_defaultLimit); } @@ -563,7 +564,7 @@ public class LogManager implements Flushable { * Size may be k, m, or g; a trailing b is ignored. Upper-case is allowed. * Spaces between the number and letter is are allowed. * The number may be in floating point. - * 4096 min, 2 GB max (returns int) + * 16K min, 2 GB max (returns int) */ public static int getFileSize(String size) { try { @@ -592,7 +593,7 @@ public class LogManager implements Flushable { // blah, noop break; } - if (val < 4096 || val > Integer.MAX_VALUE) + if (val < MIN_FILESIZE_LIMIT || val > Integer.MAX_VALUE) return -1; return (int) val; } catch (Throwable t) { -- GitLab