3

I have searched and found a lot of solutions on this subject, but all are saving the Verbose level. and not the debug or Error level ONLY

I would like to save only the debug level.

//currently the command i am using is this: 

 String[] cmd = new String[]{"logcat", "-f", filepath, "-v", "time"};

//i think it should be something like this 
 String[] cmd = new String[]{"logcat", "-f", filepath, "-v", "time", "-v" ,"tag: D/"};
Rashad.Z
  • 2,494
  • 2
  • 27
  • 58
  • possible duplicate of [Write android logcat data to a file](http://stackoverflow.com/questions/6175002/write-android-logcat-data-to-a-file) – RajSharma Jul 03 '15 at 06:35

1 Answers1

2

here's the commande line I used in my app, you just have to put "packagename:debugLevel"

LOGCATCOMMANDE = new String[] { "logcat", "-f", logFile1.getAbsolutePath(), "-r", Integer.toString(SizeOfLogFile), "-n", Integer.toString(numberOfFileRrotation), "-v", "long", "ActivityManager:W", "PACKAGENAMEHERE:D"};
        process = Runtime.getRuntime().exec(LOGCATCOMMANDE);

Hope it helps, I did spent quite a long time in finding the solution in the past ^^'

EDIT:

As mention in an other answer, do not forget the permission:

<uses-permission android:name="android.permission.READ_LOGS" />
Bxtr
  • 316
  • 1
  • 13
  • Thank you for your answer and ive been searching a lot of pages as well:p – Rashad.Z Jul 03 '15 at 06:38
  • I know, took me two to three days to find it ^^ Also just if you need to clean the logcat just before you can run LOGCATCOMMANDE = new String[] { "logcat", "-c" }; It should clean the entry you had before – Bxtr Jul 03 '15 at 06:52
  • okay thanks man. it worked for me great. can you just briefly explain the -r and -n – Rashad.Z Jul 03 '15 at 06:57
  • You can see what they're usefull for with the elements following, for example -r allows you to mention the size of the log file, and -n the number of file with which it is rotating. let's take 5 file of 10M, when the first file is full (10M) the OS will rename it in let's say "log.1" and start a new file and so on. When it reaches the max number of file you said, it will just delete the older one and create a new one ! – Bxtr Jul 05 '15 at 14:24