Util: Increase min log file size limit

Rotate the log before we hit the limit, not after
This commit is contained in:
zzz
2022-03-16 07:22:00 -04:00
parent e8afbc5b92
commit de27cb1a46
2 changed files with 6 additions and 5 deletions

View File

@ -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();
}
}

View File

@ -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) {