Reputation: 896
I'm looking for a way to save all the logcat output (Filter by tag) in phone memory/sd card. So even if someone who is playing with app, will come to me and say it crashes, or it doesn't work as intended, i could look into logs. I`m using RemoteLogs at the moment, but they not handle standard logcat output.
Upvotes: 3
Views: 2259
Reputation: 52956
You can simply dump the logcat and save it to a file by executing something like sh -c logcat -d -v time > /sdcard/logcat.txt
. In fact there are apps on the Market/Play Store that do just this and allow you to share the logcat by email, etc. It might be a good idea to instruct your users to use one of those apps (such as LogCollector) to send you the logs. An even better idea would be to use ACRA or BugSense to monitor app crashes along with environment information (Android version, screen size, etc.).
Keep in mind that since Jelly Bean (4.1) you can only access your own logcat output (i.e., from the executing app's package) when running this on the device (running via adb has more permissions and can get all logs, as before).
Yet another idea is to not use Log.x()
but write to your own log file. Recent ACRA version have the ability to send the contents of this file along with crash reports.
Upvotes: 0
Reputation: 30974
I think this is not directly possible. What you could do it to override the standard Log.x()
methods like this
class MyLog {
boolean sdLog = false;
public void d(String arg1, String arg2) {
if (sdLog) {
someLogFile.append(arg1).append(":").append(arg2);
}
else {
Log.d(arg1,arg2);
}
}
}
and then in your code replace all calls to Log.d()
with calls to MyLog.d()
. The user can then e.g. in preferences select to log to the sd card or use the standard mechanism.
Generally logging everything to the SD card was not chosen (afair) by Android, as this would mean huge amounts of writes to the card, which would reduce its lifetime.
Upvotes: 2