Fixes #3920 Send Log File" does not collect updated logs (#3958)

* Fixes #3920
* Delete stale log files post the zip file's size reaches 1000kb

* Fixes #3920
* Delete stale log files (if the size reaches more than 1000kb) on App startup to make room for fresh logs
This commit is contained in:
Ashish 2020-10-11 18:17:34 +05:30 committed by GitHub
parent 7c5fafa4aa
commit a85bd032a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,20 +188,42 @@ public class CommonsApplication extends MultiDexApplication {
*
*/
private void initTimber() {
boolean isBeta = ConfigUtils.isBetaFlavour();
String logFileName = isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs";
String logDirectory = LogUtils.getLogDirectory();
FileLoggingTree tree = new FileLoggingTree(
Log.VERBOSE,
logFileName,
logDirectory,
1000,
getFileLoggingThreadPool());
boolean isBeta = ConfigUtils.isBetaFlavour();
String logFileName =
isBeta ? "CommonsBetaAppLogs" : "CommonsAppLogs";
String logDirectory = LogUtils.getLogDirectory();
//Delete stale logs if they have exceeded the specified size
deleteStaleLogs(logFileName, logDirectory);
Timber.plant(tree);
Timber.plant(new Timber.DebugTree());
FileLoggingTree tree = new FileLoggingTree(
Log.VERBOSE,
logFileName,
logDirectory,
1000,
getFileLoggingThreadPool());
Timber.plant(tree);
Timber.plant(new Timber.DebugTree());
}
/**
* Deletes the logs zip file at the specified directory and file locations specified in the
* params
*
* @param logFileName
* @param logDirectory
*/
private void deleteStaleLogs(String logFileName, String logDirectory) {
try {
File file = new File(logDirectory + "/zip/" + logFileName + ".zip");
if (file.exists() && file.getTotalSpace() > 1000000) {// In Kbs
file.delete();
}
} catch (Exception e) {
Timber.e(e);
}
}
public static boolean isRoboUnitTest() {
return "robolectric".equals(Build.FINGERPRINT);
}