2010-07-28 90 views

回答

4

這可以通過例如使用java.util.logging類:

import android.os.Environment; 
import android.util.Log; 
     import java.util.logging.FileHandler; 
     import java.util.logging.Level; 
     import java.util.logging.LogRecord; 
     import java.util.logging.SimpleFormatter; 

     FileHandler fh=null; 
     String name; 
     if (0 == Environment.getExternalStorageState().compareTo(Environment.MEDIA_MOUNTED)) 
      name = Environment.getExternalStorageDirectory().getAbsolutePath(); 
     else 
      name = Environment.getDataDirectory().getAbsolutePath(); 

     name += "/mylogfile.log"; 

     try { 
      fh = new FileHandler(name, 256*1024, 1, true); 
      fh.setFormatter(new SimpleFormatter()); 
      fh.publish(new LogRecord(level, tag+": "+msg)); 
     } catch (Exception e) 
     { 
      Log.e("MyLog", "FileHandler exception", e); 
      return; 
     }finally{ 
      if (fh != null) 
       fh.close(); 
     } 
+0

thanx但是如果我想要捕獲系統日誌? – 2010-07-28 09:03:47

相關問題