|
@@ -406,6 +406,24 @@ public final class LogUtil {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当前使用者今天的日志文件列表,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public static List<File> getCurrentUserLogFileList(final Context context) {
|
|
|
|
|
+ return getLogFileList(context, true, true,false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当天的日志文件列表,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public static List<File> getCurrentDayLogFileList(final Context context) {
|
|
|
|
|
+ return getLogFileList(context, false, true,false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取当前使用者今天的日志文件压缩包,耗时操作,请在子线程调用
|
|
* 获取当前使用者今天的日志文件压缩包,耗时操作,请在子线程调用
|
|
@@ -445,6 +463,54 @@ public final class LogUtil {
|
|
|
return zipFile.getFile();
|
|
return zipFile.getFile();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当天的日志文件压缩包,耗时操作,请在子线程调用
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
|
|
|
|
|
+ * @throws ZipException 压缩异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public static File getCurrentDayLogFileZip(final Context context) throws ZipException {
|
|
|
|
|
+ return getCurrentDayLogFileZip(context, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当天的日志文件压缩包,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @param sideFiles 额外文件
|
|
|
|
|
+ * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
|
|
|
|
|
+ * @throws ZipException 压缩异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public static File getCurrentDayLogFileZip(final Context context, final List<File> sideFiles) throws ZipException {
|
|
|
|
|
+ return getCurrentDayLogFileZip(context, sideFiles, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当天的日志文件压缩包,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @param sideFiles 额外文件
|
|
|
|
|
+ * @param customZipFileName 压缩包名称,不包含后缀
|
|
|
|
|
+ * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
|
|
|
|
|
+ * @throws ZipException 压缩异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public static File getCurrentDayLogFileZip(final Context context, final List<File> sideFiles, final String customZipFileName) throws ZipException {
|
|
|
|
|
+ ZipFile zipFile = getLogZipFile(context, false, true,false, customZipFileName);
|
|
|
|
|
+ if (sideFiles != null && sideFiles.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(sideFiles);
|
|
|
|
|
+ }
|
|
|
|
|
+ return zipFile.getFile();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取当前使用者的所有日志文件列表,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public static List<File> getCurrentUserAllLogFileList(final Context context) {
|
|
|
|
|
+ return getLogFileList(context, true, false,false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取当前使用者的所有日志文件压缩包,耗时操作,请在子线程调用
|
|
* 获取当前使用者的所有日志文件压缩包,耗时操作,请在子线程调用
|
|
@@ -485,6 +551,15 @@ public final class LogUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 获取当前使用者昨天的日志文件列表,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public static List<File> getCurrentUserYesterdayLogFileList(final Context context) {
|
|
|
|
|
+ return getLogFileList(context, true, false,true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 获取当前使用者昨天的日志文件压缩包,耗时操作,请在子线程调用
|
|
* 获取当前使用者昨天的日志文件压缩包,耗时操作,请在子线程调用
|
|
|
*
|
|
*
|
|
|
* @param context 上下文对象
|
|
* @param context 上下文对象
|
|
@@ -525,6 +600,66 @@ public final class LogUtil {
|
|
|
return zipFile.getFile();
|
|
return zipFile.getFile();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取昨天的日志文件列表,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public static List<File> getYesterdayLogFileList(final Context context) {
|
|
|
|
|
+ return getLogFileList(context, false, false,true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取昨天的日志文件压缩包,耗时操作,请在子线程调用
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
|
|
|
|
|
+ * @throws ZipException 压缩异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public static File getYesterdayLogFileZip(final Context context) throws ZipException {
|
|
|
|
|
+ return getYesterdayLogFileZip(context, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取昨天的日志文件压缩包,耗时操作,请在子线程调用
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @param sideFiles 额外文件
|
|
|
|
|
+ * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
|
|
|
|
|
+ * @throws ZipException 压缩异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public static File getYesterdayLogFileZip(final Context context, final List<File> sideFiles) throws ZipException {
|
|
|
|
|
+ return getYesterdayLogFileZip(context, sideFiles, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取昨天的日志文件压缩包,耗时操作,请在子线程调用
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @param sideFiles 额外文件
|
|
|
|
|
+ * @param customZipFileName 压缩包名称,不包含后缀
|
|
|
|
|
+ * @return 如果存在这个文件就返回,否则根据默认的日志目录,创建一个压缩包对象,不能确定是否存在文件
|
|
|
|
|
+ * @throws ZipException 压缩异常
|
|
|
|
|
+ */
|
|
|
|
|
+ public static File getYesterdayLogFileZip(final Context context, final List<File> sideFiles, final String customZipFileName) throws ZipException {
|
|
|
|
|
+ ZipFile zipFile = getLogZipFile(context, false, false,true, customZipFileName);
|
|
|
|
|
+ if (sideFiles != null && sideFiles.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(sideFiles);
|
|
|
|
|
+ }
|
|
|
|
|
+ return zipFile.getFile();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取APP所有日志文件列表,耗时操作,请在子线程调用
|
|
|
|
|
+ * @param context 上下文对象
|
|
|
|
|
+ * @return 文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+ public static List<File> getAppAllLogFileList(final Context context) {
|
|
|
|
|
+ return getLogFileList(context, false, false, false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取APP所有日志文件压缩包,耗时操作,请在子线程调用
|
|
* 获取APP所有日志文件压缩包,耗时操作,请在子线程调用
|
|
|
*
|
|
*
|
|
@@ -599,6 +734,51 @@ public final class LogUtil {
|
|
|
return new ZipFile(logPath);
|
|
return new ZipFile(logPath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取需要的文件列表
|
|
|
|
|
+ * @param context 上下文
|
|
|
|
|
+ * @param isCurrent 当前用户
|
|
|
|
|
+ * @param isToday 是否只压缩今天
|
|
|
|
|
+ * @param isYesterday 是否只压缩明天
|
|
|
|
|
+ * @return 文件列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private static List<File> getLogFileList(final Context context, final boolean isCurrent, final boolean isToday,
|
|
|
|
|
+ final boolean isYesterday) {
|
|
|
|
|
+ File externalFileDir = context.getExternalFilesDir("XLog");
|
|
|
|
|
+ String logPath = null;
|
|
|
|
|
+ if (externalFileDir != null) {
|
|
|
|
|
+ logPath = externalFileDir.getAbsolutePath();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TextUtils.isEmpty(logPath)) {
|
|
|
|
|
+ LogUtil.i(TAG, "Log缓存目录存在");
|
|
|
|
|
+ logPath = context.getFilesDir().getPath() + "/XLog";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LogUtil.i(TAG, "Log目录存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ File logPathFile = new File(logPath);
|
|
|
|
|
+ if (logPathFile.exists()) {
|
|
|
|
|
+ if (isCurrent) {
|
|
|
|
|
+ if (isToday) {
|
|
|
|
|
+ return getCurrentTodayFileList(logPath);
|
|
|
|
|
+ } else if (isYesterday) {
|
|
|
|
|
+ return getCurrentYesterdayFileList(logPath);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return getCurrentAllFileList(logPath);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (isToday) {
|
|
|
|
|
+ return getTodayAllFileList(logPath);
|
|
|
|
|
+ } else if (isYesterday) {
|
|
|
|
|
+ return getYesterdayAllFileList(logPath);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return getAllFileList(logPath);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 创建压缩包
|
|
* 创建压缩包
|
|
|
* @param path 路径
|
|
* @param path 路径
|
|
@@ -621,14 +801,40 @@ public final class LogUtil {
|
|
|
deleteZipFile(logZipDirFile);
|
|
deleteZipFile(logZipDirFile);
|
|
|
|
|
|
|
|
ZipFile zipFile = new ZipFile(zipPath + "/" + zipFileName);
|
|
ZipFile zipFile = new ZipFile(zipPath + "/" + zipFileName);
|
|
|
- if (isCurrent && isToday) {
|
|
|
|
|
- getCurrentToday(zipFile, path);
|
|
|
|
|
- } else if (isCurrent && isYesterday) {
|
|
|
|
|
- getCurrentYesterday(zipFile, path);
|
|
|
|
|
- } else if (isCurrent) {
|
|
|
|
|
- getCurrentAll(zipFile, path);
|
|
|
|
|
|
|
+ if (isCurrent) {
|
|
|
|
|
+ if (isToday) {
|
|
|
|
|
+ List<File> currentTodayFileList = getCurrentTodayFileList(path);
|
|
|
|
|
+ if (currentTodayFileList.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(currentTodayFileList);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (isYesterday) {
|
|
|
|
|
+ List<File> currentYesterdayFileList = getCurrentYesterdayFileList(path);
|
|
|
|
|
+ if (currentYesterdayFileList.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(currentYesterdayFileList);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<File> currentAllFileList = getCurrentAllFileList(path);
|
|
|
|
|
+ if (currentAllFileList.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(currentAllFileList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- getAll(zipFile, path);
|
|
|
|
|
|
|
+ if (isToday) {
|
|
|
|
|
+ List<File> todayFileList = getTodayAllFileList(path);
|
|
|
|
|
+ if (todayFileList.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(todayFileList);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (isYesterday) {
|
|
|
|
|
+ List<File> yesterdayFileList = getYesterdayAllFileList(path);
|
|
|
|
|
+ if (yesterdayFileList.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(yesterdayFileList);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<File> allFileList = getAllFileList(path);
|
|
|
|
|
+ if (allFileList.size() > 0) {
|
|
|
|
|
+ zipFile.addFiles(allFileList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return zipFile;
|
|
return zipFile;
|
|
|
}
|
|
}
|
|
@@ -636,11 +842,64 @@ public final class LogUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 获取以一些字符串开头的文件名的文件
|
|
|
|
|
+ * @param startsWithName 需要的文件名开头集合
|
|
|
|
|
+ * @param path 日志目录
|
|
|
|
|
+ * @return 需要的文件
|
|
|
|
|
+ */
|
|
|
|
|
+ private static List<File> getStartsWithStringFile(final List<String> startsWithName, final String path) {
|
|
|
|
|
+ List<File> needLogFile = new ArrayList<>();
|
|
|
|
|
+ File logPathFile = new File(path);
|
|
|
|
|
+ File[] logFiles = logPathFile.listFiles();
|
|
|
|
|
+ if (logFiles != null) {
|
|
|
|
|
+ List<File> logFileList = Arrays.asList(logFiles);
|
|
|
|
|
+ for (File logFile: logFileList) {
|
|
|
|
|
+ boolean isNeed = false;
|
|
|
|
|
+ for (String name: startsWithName) {
|
|
|
|
|
+ if (logFile.getName().startsWith(name)) {
|
|
|
|
|
+ isNeed = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isNeed) {
|
|
|
|
|
+ needLogFile.add(logFile);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return needLogFile;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取包含一些字符串的文件名的文件
|
|
|
|
|
+ * @param containsName 需要的包含的字符集合
|
|
|
|
|
+ * @param path 日志目录
|
|
|
|
|
+ * @return 需要的文件
|
|
|
|
|
+ */
|
|
|
|
|
+ private static List<File> getContainsStringFile(final List<String> containsName, final String path) {
|
|
|
|
|
+ List<File> needLogFile = new ArrayList<>();
|
|
|
|
|
+ File logPathFile = new File(path);
|
|
|
|
|
+ File[] logFiles = logPathFile.listFiles();
|
|
|
|
|
+ if (logFiles != null) {
|
|
|
|
|
+ List<File> logFileList = Arrays.asList(logFiles);
|
|
|
|
|
+ for (File logFile: logFileList) {
|
|
|
|
|
+ boolean isNeed = false;
|
|
|
|
|
+ for (String name: containsName) {
|
|
|
|
|
+ if (logFile.getName().contains(name)) {
|
|
|
|
|
+ isNeed = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isNeed) {
|
|
|
|
|
+ needLogFile.add(logFile);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return needLogFile;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 获取当前用户今天的日志
|
|
* 获取当前用户今天的日志
|
|
|
- * @param zipFile 压缩文件
|
|
|
|
|
* @param path 日志目录
|
|
* @param path 日志目录
|
|
|
*/
|
|
*/
|
|
|
- private static void getCurrentToday(final ZipFile zipFile, final String path) throws ZipException {
|
|
|
|
|
|
|
+ private static List<File> getCurrentTodayFileList(final String path) {
|
|
|
List<String> startsWithName = new ArrayList<>();
|
|
List<String> startsWithName = new ArrayList<>();
|
|
|
//主日志文件
|
|
//主日志文件
|
|
|
String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + dateToDay(new Date());
|
|
String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + dateToDay(new Date());
|
|
@@ -653,16 +912,14 @@ public final class LogUtil {
|
|
|
String logFileNameRelease = "Release__" + dateToDay(new Date());
|
|
String logFileNameRelease = "Release__" + dateToDay(new Date());
|
|
|
startsWithName.add(logFileNameRelease);
|
|
startsWithName.add(logFileNameRelease);
|
|
|
}
|
|
}
|
|
|
- List<File> logFiles = getStartsWithStringFile(startsWithName, path);
|
|
|
|
|
- zipFile.addFiles(logFiles);
|
|
|
|
|
|
|
+ return getStartsWithStringFile(startsWithName, path);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取当前用户昨天的日志
|
|
* 获取当前用户昨天的日志
|
|
|
- * @param zipFile 压缩文件
|
|
|
|
|
* @param path 日志目录
|
|
* @param path 日志目录
|
|
|
*/
|
|
*/
|
|
|
- private static void getCurrentYesterday(final ZipFile zipFile, final String path) throws ZipException {
|
|
|
|
|
|
|
+ private static List<File> getCurrentYesterdayFileList(final String path) {
|
|
|
List<String> startsWithName = new ArrayList<>();
|
|
List<String> startsWithName = new ArrayList<>();
|
|
|
//主日志文件
|
|
//主日志文件
|
|
|
String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(1, "yyyyMMdd");
|
|
String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(1, "yyyyMMdd");
|
|
@@ -675,16 +932,14 @@ public final class LogUtil {
|
|
|
String logFileNameRelease = "Release__" + getPastDate(1, "yyyyMMdd");
|
|
String logFileNameRelease = "Release__" + getPastDate(1, "yyyyMMdd");
|
|
|
startsWithName.add(logFileNameRelease);
|
|
startsWithName.add(logFileNameRelease);
|
|
|
}
|
|
}
|
|
|
- List<File> logFiles = getStartsWithStringFile(startsWithName, path);
|
|
|
|
|
- zipFile.addFiles(logFiles);
|
|
|
|
|
|
|
+ return getStartsWithStringFile(startsWithName, path);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取当前用户所有的日志
|
|
* 获取当前用户所有的日志
|
|
|
- * @param zipFile 压缩文件
|
|
|
|
|
* @param path 日志目录
|
|
* @param path 日志目录
|
|
|
*/
|
|
*/
|
|
|
- private static void getCurrentAll(final ZipFile zipFile, final String path) throws ZipException {
|
|
|
|
|
|
|
+ private static List<File> getCurrentAllFileList(final String path) {
|
|
|
List<String> startsWithName = new ArrayList<>();
|
|
List<String> startsWithName = new ArrayList<>();
|
|
|
//主日志文件
|
|
//主日志文件
|
|
|
String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix();
|
|
String logStartsWith = MarsXLogInit.getInstance().getLogFileNamePrefix();
|
|
@@ -697,48 +952,38 @@ public final class LogUtil {
|
|
|
String logFileNameRelease = "Release__";
|
|
String logFileNameRelease = "Release__";
|
|
|
startsWithName.add(logFileNameRelease);
|
|
startsWithName.add(logFileNameRelease);
|
|
|
}
|
|
}
|
|
|
- List<File> logFiles = getStartsWithStringFile(startsWithName, path);
|
|
|
|
|
- zipFile.addFiles(logFiles);
|
|
|
|
|
|
|
+ return getStartsWithStringFile(startsWithName, path);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 获取所有用户所有的日志
|
|
|
|
|
- * @param zipFile 压缩文件
|
|
|
|
|
|
|
+ * 获取所有用户今天的日志
|
|
|
* @param path 日志目录
|
|
* @param path 日志目录
|
|
|
*/
|
|
*/
|
|
|
- private static void getAll(final ZipFile zipFile, final String path) throws ZipException {
|
|
|
|
|
- File logPathFile = new File(path);
|
|
|
|
|
- File[] logFiles = logPathFile.listFiles();
|
|
|
|
|
- if (logFiles != null) {
|
|
|
|
|
- zipFile.addFiles(Arrays.asList(logFiles));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private static List<File> getTodayAllFileList(final String path) {
|
|
|
|
|
+ List<String> containsName = new ArrayList<>();
|
|
|
|
|
+ containsName.add(dateToDay(new Date()));
|
|
|
|
|
+ return getContainsStringFile(containsName, path);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 获取以一些字符串开头的文件名的文件
|
|
|
|
|
- * @param startsWithName 需要的文件名开头集合
|
|
|
|
|
|
|
+ * 获取所有用户昨天的日志
|
|
|
* @param path 日志目录
|
|
* @param path 日志目录
|
|
|
- * @return 需要的文件
|
|
|
|
|
*/
|
|
*/
|
|
|
- private static List<File> getStartsWithStringFile(final List<String> startsWithName, final String path) {
|
|
|
|
|
- List<File> needLogFile = new ArrayList<>();
|
|
|
|
|
|
|
+ private static List<File> getYesterdayAllFileList(final String path) {
|
|
|
|
|
+ List<String> containsName = new ArrayList<>();
|
|
|
|
|
+ String logStartsWith = getPastDate(1, "yyyyMMdd");
|
|
|
|
|
+ containsName.add(logStartsWith);
|
|
|
|
|
+ return getContainsStringFile(containsName, path);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取所有用户所有的日志
|
|
|
|
|
+ * @param path 日志目录
|
|
|
|
|
+ */
|
|
|
|
|
+ private static List<File> getAllFileList(final String path) {
|
|
|
File logPathFile = new File(path);
|
|
File logPathFile = new File(path);
|
|
|
File[] logFiles = logPathFile.listFiles();
|
|
File[] logFiles = logPathFile.listFiles();
|
|
|
- if (logFiles != null) {
|
|
|
|
|
- List<File> logFileList = Arrays.asList(logFiles);
|
|
|
|
|
- for (File logFile: logFileList) {
|
|
|
|
|
- boolean isNeed = false;
|
|
|
|
|
- for (String name: startsWithName) {
|
|
|
|
|
- if (logFile.getName().startsWith(name)) {
|
|
|
|
|
- isNeed = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (isNeed) {
|
|
|
|
|
- needLogFile.add(logFile);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return needLogFile;
|
|
|
|
|
|
|
+ return Arrays.asList(logFiles);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -753,22 +998,30 @@ public final class LogUtil {
|
|
|
final boolean isToday, final boolean isYesterday, final String customZipFileName) {
|
|
final boolean isToday, final boolean isYesterday, final String customZipFileName) {
|
|
|
String zipFileName;
|
|
String zipFileName;
|
|
|
if (TextUtils.isEmpty(customZipFileName)) {
|
|
if (TextUtils.isEmpty(customZipFileName)) {
|
|
|
- if (isCurrent && isToday) {
|
|
|
|
|
- zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
- } else if (isCurrent && isYesterday) {
|
|
|
|
|
- zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(1, "yyyyMMdd") + ".zip";
|
|
|
|
|
- } else if (isCurrent) {
|
|
|
|
|
- if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
|
|
|
|
|
- zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
|
|
+ if (isCurrent) {
|
|
|
|
|
+ if (isToday) {
|
|
|
|
|
+ zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
+ } else if (isYesterday) {
|
|
|
|
|
+ zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(1, "yyyyMMdd") + ".zip";
|
|
|
} else {
|
|
} else {
|
|
|
- zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
|
|
+ if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
|
|
|
|
|
+ zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ zipFileName = MarsXLogInit.getInstance().getLogFileNamePrefix() + "_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
String fileNamePrefix = MarsXLogInit.getInstance().getLogFileNamePrefix().substring(0, MarsXLogInit.getInstance().getLogFileNamePrefix().indexOf("_"));
|
|
String fileNamePrefix = MarsXLogInit.getInstance().getLogFileNamePrefix().substring(0, MarsXLogInit.getInstance().getLogFileNamePrefix().indexOf("_"));
|
|
|
- if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
|
|
|
|
|
- zipFileName = fileNamePrefix + "_all_user_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
|
|
+ if (isToday) {
|
|
|
|
|
+ zipFileName = fileNamePrefix + "_all_user_" + "_" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
+ } else if (isYesterday) {
|
|
|
|
|
+ zipFileName = fileNamePrefix + "_all_user_" + "_" + getPastDate(1, "yyyyMMdd") + ".zip";
|
|
|
} else {
|
|
} else {
|
|
|
- zipFileName = fileNamePrefix + "_all_user_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
|
|
+ if (MarsXLogInit.getInstance().getLogFileSaveDays() == 0) {
|
|
|
|
|
+ zipFileName = fileNamePrefix + "_all_user_" + getPastDate(10, "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ zipFileName = fileNamePrefix + "_all_user_" + getPastDate(MarsXLogInit.getInstance().getLogFileSaveDays(), "yyyyMMdd") + "~" + dateToDay(new Date()) + ".zip";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|