2017-07-25 61 views
0

這是我如何從應用程序日誌:的Java的Android獲取日誌文件

try { 
      SimpleDateFormat sdf = new SimpleDateFormat(
        "yyyy-MM-dd", Locale.US); 
      String currentDateandTime = sdf.format(new Date()); 
      final File path = new File(Environment.getExternalStorageDirectory(), "SMOK_komunal"); 
      if (!path.exists()) { 
       path.mkdir(); 
      } 
      Log.e("path ", path.getAbsolutePath()); 
      Runtime.getRuntime().exec("logcat -f " + path + File.separator + "dbo_logcat_" + currentDateandTime + ".txt"); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

但在這個日誌我沒有在線路如何添加日期和時間的日期和時間?

回答

1

爲獲得日期和時間打印日誌是這樣的:

Log.e("path ", path.getAbsolutePath()+ " and "+currentDateandTime); 

它會給兩個文件路徑和日期和時間