清除日志

hdrplus
Matthew 12 months ago
parent 2cf1ed9c6d
commit a8df6e3094

@ -319,6 +319,12 @@ public class AppMaster {
e.printStackTrace();
}
try {
mService.cleanLogFiles();
} catch (Exception ex) {
ex.printStackTrace();
}
return res;
}

@ -101,6 +101,8 @@ public class MpMasterService extends Service {
private int mQuickHeartbeatDuration = 60; // Unit: second
private int mHeartbeatDuration = 600; // 10m = 10 * 60s
private long mTimeForKeepingLogs = 86400000 * 15; // 15 days
private AlarmReceiver mAlarmReceiver = null;
private ScreenActionReceiver mScreenaAtionReceiver = null;
private UpdateReceiver mUpdateReceiver = null;
@ -164,7 +166,7 @@ public class MpMasterService extends Service {
fi.mkdirs();
}
File logFile = new File(fi, "log.txt");
File logFile = new File(fi, "mlog.txt");
rotatingHandler = new RotatingHandler(logFile.getAbsolutePath(), logFormatter);
@ -242,6 +244,31 @@ public class MpMasterService extends Service {
}
}
public void cleanLogFiles() {
try {
String appPath = MicroPhotoContext.buildMasterAppDir(getApplicationContext());
String logPath = appPath + "logs";
File fi = new File(logPath);
if (!fi.exists()) {
return;
}
Date dt = new Date();
dt.setHours(0);
dt.setMinutes(0);
long millis = dt.getTime() - mTimeForKeepingLogs;
File[] subFiles = fi.listFiles();
for (File f : subFiles) {
if (f.lastModified() < millis) {
f.delete();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void onDestroy() {

Loading…
Cancel
Save