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:
- Dump the Logs into the file with simple command.
- 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:
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.
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"); filename.createNewFile(); Log.i(" Logcat ", " ----- Dumping Logs ----- "); String cmd = "logcat -d -f " + filename.getAbsolutePath(); Runtime.getRuntime().exec(cmd);
Yuo should put in try block.