添加LogUtils日志文件自动裁剪功能
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Mon Apr 27 20:19:11 HKT 2026
|
||||
#Tue Apr 28 17:02:01 CST 2026
|
||||
stageCount=21
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.20
|
||||
buildCount=0
|
||||
buildCount=7
|
||||
baseBetaVersion=15.15.21
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Mon Apr 27 20:18:59 HKT 2026
|
||||
#Tue Apr 28 17:02:01 CST 2026
|
||||
stageCount=21
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.15
|
||||
publishVersion=15.15.20
|
||||
buildCount=0
|
||||
buildCount=7
|
||||
baseBetaVersion=15.15.21
|
||||
|
||||
@@ -100,10 +100,52 @@ public class LogUtils {
|
||||
// 加载当前应用下的所有类的 TAG
|
||||
addClassTAGList();
|
||||
loadTAGBeanSettings();
|
||||
checkAndTrimLogFileSize();
|
||||
_IsInited = true;
|
||||
LogUtils.d(TAG, String.format("mapTAGList : %s", mapTAGList.toString()));
|
||||
}
|
||||
|
||||
private static void checkAndTrimLogFileSize() {
|
||||
if (_mfLogCatchFile == null || !_mfLogCatchFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final long MAX_FILE_SIZE = 6291456L;
|
||||
final long KEEP_FILE_SIZE = 3145728L;
|
||||
|
||||
long fileSize = _mfLogCatchFile.length();
|
||||
if (fileSize <= MAX_FILE_SIZE) {
|
||||
return;
|
||||
}
|
||||
|
||||
long needSkip = fileSize - KEEP_FILE_SIZE;
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(_mfLogCatchFile);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
|
||||
FileOutputStream fos = new FileOutputStream(_mfLogCatchFile);
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos))) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
long skippedTotal = 0;
|
||||
final String lineBreak = System.lineSeparator();
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
byte[] lineBytes = line.getBytes();
|
||||
skippedTotal += lineBytes.length + lineBreak.getBytes().length;
|
||||
|
||||
if (skippedTotal > needSkip) {
|
||||
sb.append(line).append(lineBreak);
|
||||
}
|
||||
}
|
||||
|
||||
writer.write(sb.toString());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Boolean> getMapTAGList() {
|
||||
return mapTAGList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user