views:

36

answers:

1

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

+2  A: 

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();
        }
Thorstenvv
thanx but wat if i want to capture the system log also?
Santhosh