virsir
virsir

Reputation: 15509

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 it in the sd card for further check.

Upvotes: 0

Views: 1530

Answers (3)

inazaruk
inazaruk

Reputation: 74790

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).

Upvotes: 2

includeMe
includeMe

Reputation: 2672

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.

Upvotes: 1

bluefalcon
bluefalcon

Reputation: 4245

Did you try dumping the log to a file?

adb logcat > log.txt

Upvotes: 0

Related Questions