I have gotto put huge logs so the logfile keeps growing. At some time it will be difficult to go through the complete log file . Coming to the point. I need to have rollover of log concept in android just like we do in java. I see there is a option in android . The fallowing is the command but it doesnt seem working. "logcat -v time -f " + path + "LogCatFileName.txt -r 1000 -n 3 ". this command creates 5 logcat files irrespective of "-n " and creates 16kb size of every file irrespective of "-r". Looks like default value of these variables are not changing. Can someone help me resolve this?


Well, i think there is a limit for logcat size. So after some time you will not be able to reach the logs from a year ago. The other thing you can do is:

  1. Dump the Logs into the file with simple command.
  2. Clear logs after that.

With those actions you have clean logs always and files that contains the data. I don't know how you want to do this, with ADB or inside the phone with app.

with ADB: Creating the file with logs:

adb shell

logcat -d > [place where u want to place logs in device]

Cleaning the logcat:

adb shell logcat -c

Then you can pull the logs from the phone with ADB command or you can jsut find them in the phone.

Command is:

adb pull [place where are the logs - like /sdcard/logz.txt]

This will get the file and place it in the directory of your terminal that you currently work.

Getting logs with application:

File filename = new File(Environment.getExternalStorageDirectory() + "/direcotry/" + [save_date or randomly generated number] + ".log");
Log.i(" Logcat ", " ----- Dumping Logs ----- ");
String cmd = "logcat -d -f " + filename.getAbsolutePath();

Yuo should put in try block.

  • I use the this command " Runtime.getRuntime().exec("logcat -v time -f " +" path/LogCat.txt");" and it works fine .But the size of the file is getting increased and it will be difficult to analyze the crashes or any bugs if we get. So Now i am using this command "Runtime.getRuntime().exec("logcat -v time -f " +" path/LogCat.txt -r 1000 -n 3"); " which should create 3 files with 1000kbs and keeps rotating the files. Instead the values of "-r " ie. 1000(in kbs) , "-n " ie 3 no of files seems not considered. It is using the default values of -r=16kb and -n=5 files. Is this the bug with android? – Pruthvi Sep 16 '15 at 10:29
  • In documentation the -n default is 4. And the Default of -r is 16kb. Have you tried to put the -f at the end of the command ? After describing the size and limit that it should make ? try: " logcat -v time -r 1000 -n 3 -f " +" path/LogCat.txt " – Fransis Q Sep 16 '15 at 11:33
  • Ya default values for -n is 4. Leaving the actual file it will create 4 more files. LogCat,LogCat1,LogCat2,LogCat3,LogCat4. I have tried altering the places of commands as u said . If i use " logcat -v time -r 1000 -n 3 -f " +" path/LogCat.txt " the logCat file will not create itself. – Pruthvi Sep 16 '15 at 13:48
  • I checked your command it works for me, my Log file have 739KB and it is not splitted into little files, you know that if you leave the command like this the logcat is always ON and it saves to the files all the time the logs ? But I've added the -d so the LogCat can just at once put all the stuff it has inside into the files and not work in background. Try the command like: "logcat -d -v time -f /sdcard/loggcat.txt -r 1000 -n 3" Maybe this output will be satisfying for you. – Fransis Q Sep 16 '15 at 14:45
  • First of all i have cleared the logcat with logcat -c , then I have run the command: " logcat -d -v time -f /sdcard/loggcat.txt -r 200 " And it works perfect. The size of logcat file is 394 KB and its splitted into two parts, one 194,3KB and one 200KB. As you can see I've removed the "-n" parameter and it worked great. Also i've added the -d to dump the logs into the file and exit LogCat. – Fransis Q Sep 16 '15 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.