Skip to content

Commit

Permalink
日志添加版本信息
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed May 31, 2017
1 parent 09eb8f3 commit c17acd1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,22 @@ private void dumpExceptionToSDCard(Throwable ex) throws IOException {
dir.mkdirs();
}
long current = System.currentTimeMillis();
//版本号
String version = "";
try {
PackageManager pm = mContext.getPackageManager();
PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_ACTIVITIES);
version = "V" + pi.versionName + "_";
} catch (Exception e) {

}
//时间
String time = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date(current));

time = "T" + time;

//以当前时间创建log文件
File file = new File(dir, "CrashLog_" + time.trim() + FILE_NAME_SUFFIX);
File file = new File(dir, "CrashLog_" + version + time.trim() + FILE_NAME_SUFFIX);
if (!file.exists()) {
file.createNewFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void initViews() {
recycleView_search = (RecyclerView) findViewById(R.id.recycleView_search);
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);

initToolBar(toolbar,"崩溃日志列表");
initToolBar(toolbar, "崩溃日志列表");

recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
Expand All @@ -94,9 +94,7 @@ private void initCrashFileList() {
new Thread(new Runnable() {
@Override
public void run() {

getCrashList();

}
}).start();

Expand All @@ -111,16 +109,27 @@ private void getCrashList() {
Collections.sort(fileList, new Comparator<File>() {
@Override
public int compare(File file01, File file02) {
String date01 = file01.getName().substring(9, file01.getName().length() - 4);
String date02 = file02.getName().substring(9, file02.getName().length() - 4);
//时间转换为毫秒
int time01 = Integer.parseInt(MDateUtil.dataToTime(date01));
int time02 = Integer.parseInt(MDateUtil.dataToTime(date02));
if (time01 > time02) {
return -1;
String[] file01_array = file01.getName().split("T");
String[] file02_array = file02.getName().split("T");
if (file01_array.length > 1 && file02_array.length > 1) {
String date01 = file01_array[1];
String date02 = file02_array[1];
try {
//时间转换为毫秒
int time01 = Integer.parseInt(MDateUtil.dataToTime(date01));
int time02 = Integer.parseInt(MDateUtil.dataToTime(date02));
if (time01 > time02) {
return -1;
} else {
return 1;
}
} catch (Exception e) {
return 1;
}
} else {
return 1;
}

}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public static String getCrashLogPath(Context context) {
public static List<File> getFileList(File file) {
List<File> mFileList = new ArrayList<>();
File[] fileArray = file.listFiles();
if (fileArray == null || fileArray.length <= 0) {
return mFileList;
}
for (File f : fileArray) {
if (f.isFile()) {
mFileList.add(f);
Expand Down

0 comments on commit c17acd1

Please sign in to comment.