开发者

How to keep android device log from not being cleared?

I want to dump all logs out to test a long usage of my app, maybe 2-3 days, but the logs seem to be cleared out while running after a long time.

How can I keep the logs?

I do not want to connect my device with eclipse all the day, I want the log just keep for me, like store i开发者_JAVA百科t in the sd card for further check.


I had same requirement for my application. By default there is logcat process that tracks logs up to around 64kb (depends on device).

You can start your own logcat process using adb shell with some custom arguments. For example:

adb shell logcat -f /mnt/sdcard/large.log -r 100 -n 10

This will save up to 1mb of logs evenly distributed among 10 files (large.log, large.log.0, larget.log.1, etc.);

The next step is to launch logcat from your application:

String [] args = new String[] { Logcat, "-v", "threadtime", 
                                "-f", logFile.getAbsolutePath(),
                                "-r", Integer.toString(sizePerFile),
                                "-n", Integer.toString(rotationCount),
                                "*:"+filter}; 

Runtime.getRuntime().exec(args);

So now your app may start saving logs. But you should be careful not to enable this in your production versions of application (or at least make this opt-in feature).


Instead of using the eclipse log use the apps like 'log viewer'. I think that app can solve your issue. I think the log will remain until you clear the log manually in 'log viewer'. I just downloaded it today morning and still has the logs of actions I performed just after I switched on the device.


Did you try dumping the log to a file?

adb logcat > log.txt

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜