Tutorial :How to generate external logfile in android app?



Question:

may i know is there any way to generate external log file?


Solution:1

This can be done e.g. with java.util.logging classes:

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();          }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »