[core] Truncate log if log file is too big (#202)

This commit is contained in:
LoveSy 2021-02-26 12:22:05 +08:00 committed by GitHub
parent ddeb375c21
commit ec50521554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -44,6 +44,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
@ -544,8 +545,13 @@ public class ConfigManager {
public ParcelFileDescriptor getModulesLog(int mode) {
try {
if (modulesLogPath.length() > 4000 * 1024) {
try (FileChannel outChan = new FileOutputStream(modulesLogPath, true).getChannel()) {
outChan.truncate(1000 * 1024);
}
}
return ParcelFileDescriptor.open(modulesLogPath, mode | ParcelFileDescriptor.MODE_CREATE);
} catch (FileNotFoundException e) {
} catch (IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
return null;
}