Hi, I am not aware of any methods either. I worked around this by creating numbered versions of the log file using an ErrorLogger class. The user can request the server application to close the current version of the log file and open a new one. This would then allow you to archive or delete the old ones. The code for a couple of the methods from this class are attached. The openLogFile method that is used to lookfor the next log file is attached. The logFileprefix is a public variable that sets the path and prefix of the log file. e.g. c:/someplace/LogStuff which with the suffix generates a name of c:/someplace/LogStuff000.log.
You can create your own logMsg method which counts lines, and automatically opens a new log file once your 'limit' has been reached, or on a daily basis, or whatever.
Its not elegant, but I hope it helps.
Neil
/**
* Opens a new log file for logging messages.
* This method will create numbered logfiles in sequence. It takes the logfile prefix and extension
* that it has been given previously, and looks for the highest number logfile in the directory. It then increments
* this number by one and opens a new log file with that number. If a Log File is already open
* it closes the existing file first.
* @return void
* @Exception IOException thrown for usual file-related errors including path not found, etc.
*/
public static void openLogFile() throws IOException {
String versionNumber;
if (currentVersion==0) {
int version;
int versionFnd=0;
File logFile = new File(logFilePrefix);
String prefix = logFile.getName();
int prefixLen = prefix.length();
String parentDir=logFile.getParent();
if (parentDir==null) parentDir = ".";
File dir = new File(parentDir);
// Find highest file version
String logFiles[] = dir.list();
int prefixFnd=0;
if (logFiles!=null) {
for (int ptr = 0;ptr < logFiles.length;ptr++) {
if ((prefixFnd=logFiles[ptr].indexOf(prefix))>=0) {
// The following assumes that the version is always 3 digits
versionNumber = logFiles[ptr].substring(prefixFnd+prefixLen,logFiles[ptr].indexOf("."));
try {
version = Integer.parseInt(versionNumber);
} catch (NumberFormatException e) { version = 0;}
if (version>versionFnd) versionFnd = version;
}
}
} else
versionFnd = 0;
currentVersion = versionFnd; // This is the highest number found
}
if (currentVersion>=999) currentVersion=0; // Wrap at 999
// increment highest version by 1
versionNumber=String.valueOf(++currentVersion);
while (versionNumber.length()<3) { versionNumber = "0" + versionNumber; }
logFile = logFilePrefix + versionNumber + extension;
if (outputStream != null) closeLogFile();
outputStream = new FileOutputStream(logFile);
logToFile = true;
logMsg("Opened log file: " + logFile);
}
/**
* Close the Log file - ignore any errors that occur.
* @return void
*/
public static void closeLogFile() {
try {
logMsg("Closing log file: " + logFile);
logToFile = false;
outputStream.close();
} catch (IOException e) { /* Ignore it */ }
}