1

I want to save logcat values, specifically LOG.I, of my application in sdcard. I have used following code to get all log values but unable to filter it to get only specific log.i values. Please suggest how to do it?

 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();
        }
Oak Bytes
  • 4,649
  • 4
  • 36
  • 53
suprita
  • 211
  • 1
  • 9

2 Answers2

2

Update:

Just change your code,

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

with

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

you don't have to create file by your self just execute the above command, to get the Your application's specific tag info.

Here

-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.
user370305
  • 108,599
  • 23
  • 164
  • 151
  • I have used bellow codebut it shows blank html file *************try { File filename = new File(Environment.getExternalStorageDirectory()+"/gphoto4.html"); filename.createNewFile(); String cmd = "logcat [TAG]:I [MyApp]:D *:S"+filename.getAbsolutePath(); Runtime.getRuntime().exec(cmd); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } – suprita Jul 03 '12 at 12:54
  • Actually this works in my case, "logcat [TAG]:I [MyApp]:D *:S > /mnt/sdcard/log.out" – user370305 Jul 03 '12 at 13:05
0

May not be a direct answer, but I think this can be useful for you Application Crash Report for Android,

I have used this in some of my projects it works like wonder.

Amit
  • 13,134
  • 17
  • 77
  • 148