IDEMPIERE-4619 Improve CLogger fallback when reaching 100 files in /log folder (#492)

This commit is contained in:
Carlos Ruiz 2020-12-30 13:22:36 +01:00 committed by GitHub
parent 45cfbe6804
commit 055ad2f0ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 6 deletions

View File

@ -138,16 +138,16 @@ public class CLogFile extends Handler
// Test/Create idempiereHome/log/file
if (fileName != null)
{
fileName += File.separator;
String dateFileName = fileName + File.separator;
if (isClient)
fileName += "client.";
dateFileName += "client.";
else
fileName += "idempiere.";
dateFileName += "idempiere.";
m_fileNameDate = getFileNameDate(System.currentTimeMillis());
fileName += m_fileNameDate + "_";
for (int i = 0; i < 100; i++)
dateFileName += m_fileNameDate + "_";
for (int i = 0; i < 100; i++) // max 100 files with date
{
String finalName = fileName + i + ".log";
String finalName = dateFileName + i + ".log";
File file = new File(finalName);
if (!file.exists())
{
@ -156,7 +156,22 @@ public class CLogFile extends Handler
}
}
}
if (m_file == null) { // Fallback to date+time filename
String timeFileName = fileName + File.separator;
if (isClient)
timeFileName += "client.";
else
timeFileName += "idempiere.";
String fileNameTime = getFileNameDateTime(System.currentTimeMillis());
String finalName = timeFileName + fileNameTime + ".log";
File file = new File(finalName);
if (!file.exists())
{
m_file = file;
}
}
if (m_file == null) { // Fallback create temp file
// would be very weird to arrive here, but preserving anyways as an extra fallback measure
m_fileNameDate = getFileNameDate(System.currentTimeMillis());
m_file = File.createTempFile("idempiere"+m_fileNameDate + "_", ".log");
}
@ -182,6 +197,19 @@ public class CLogFile extends Handler
return s.substring(0, 10);
} // getFileNameDate
/**
* Get File Name DateTime portion
* @param time time in ms
* @return DateTime String on Seconds
*/
public static String getFileNameDateTime (long time)
{
Timestamp ts = new Timestamp(time);
String s = ts.toString();
s = s.replaceAll("[ :]", "-");
return s.substring(0, 19); // seconds
} // getFileNameDate
/**
* Rotate Log when day changes
* @param time time