2012-07-03 24 views
1

我想將我的應用程序的logcat值,特別是LOG.I保存在SD卡中。 我已經使用以下代碼來獲取所有日誌值,但無法過濾它只獲得特定的log.i值。請建議如何做?如何只從應用程序的logcat獲取log.i值?

try { 
     File filename = new File(Environment.getExternalStorageDirectory()+"/gphoto4.html"); 
      filename.createNewFile(); 
      String cmd = "logcat -d -f "+filename.getAbsolutePath(); 
      Runtime.getRuntime().exec(cmd); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
+0

確定我VILL提高。如果你知道如何獲取日誌值。 Plz告訴。 – suprita

+0

@imran khan:感謝回覆 – suprita

+0

@android_pb:你的問題得到解決或沒有? –

回答

0

可能不是一個直接的答案,但我覺得這可能是對你有用​​,

我已經在我的一些項目,它的工作原理一樣的好奇心用這個。

+0

感謝您的回覆,但實際上我想只在SD卡中保存LOG.I值。 – suprita

+0

在這種情況下,你有沒有嘗試在另一個答案中提供的解決方案@ user370305 – aProgrammer

2

更新:

只要改變你的代碼,

String cmd = "logcat -d -f "+filename.getAbsolutePath(); 

String cmd = "logcat -v time -r 100 -f <filename> [TAG]:I [MyApp]:D *:S"; 
Runtime.getRuntime().exec(cmd); 

你沒有通過你自己創建的文件只是執行上面的命令,以獲取您的應用程序的特定標籤信息。

這裏

-v -> Sets the output format for log messages. 
-r -> for specifying the size of file. 
-f -> file to which you want to write the logs. 
[TAG] -> Tag of your application's log. 
[MyApp] -> Your application name. 
+0

我已經使用bellow codebut但它顯示空白html文件*************嘗試{File filename = new File(Environment.getExternalStorageDirectory ()+ 「/ gphoto4.html」); \t \t filename.createNewFile(); \t \t String cmd =「logcat [TAG]:I [MyApp]:D *:S」+ filename.getAbsolutePath(); \t \t Runtime.getRuntime()。exec(cmd); \t \t}趕上(IOException的發送){ \t \t // TODO自動生成的catch程序塊 \t \t e.printStackTrace(); \t \t} – suprita

+0

其實這在我的情況下,「logcat [標籤]:我[MyApp]:D *:S> /mnt/sdcard/log.out」 – user370305

+0

看看我更新的答案,完整的解決方案。 – user370305

相關問題