I have an application/phone which I am developing to be given to people who will be using it in remote areas and not so tech-savvy. I want a mechanism to be able to read their log files remotely. The android app is making use of the logcat logging. I want to be able to just read my logs for my app by some remote mechanism. I was thinking more along the lines of reading the logcat then posting that up periodically to a REST service where I can database these. So question is how do I read the Logcat files programatically from my app?
Asked
Active
Viewed 1,252 times
0
-
The `logcat` typically has a ton of information logged in it by the OS and by poorly written apps that (shouldn't) log everything by default. Unless you can setup filtering you are going to be sending a lot of extra log information you don't need. If you only need to view logs for your own app, I'd consider just outputting your app's log to a standalone file that you periodically send to a web server. If you're users are in remote areas with poor data connections, the less info you have to transmit the better. – Jake Wilson Jan 24 '12 at 18:13
-
@Jakobud Okay so how do I do that? – JPM Jan 24 '12 at 19:40
1 Answers
1
If you invoke:
Proccess p = Runtime.getRuntime().exec("logcat");
InputStream in = p.getInputStream();
//code to process the InputStream
I honestly do not know the entire process of getting the input stream back, but the code above will allow your app to read the logcat file. You can go here for possible command-line paramaters for "logcat". The exec
method runs the string through a linux shell, btw.
You must have the permission READ_LOGS

Reed
- 14,703
- 8
- 66
- 110
-
@JPM I believe you're correct. So use a thread and a handler. I honestly don't know the whole process of outputing log files, I just know that what I put in my answer should give you a decent starting point. You could also use [ACRA](http://code.google.com/p/acra/wiki/AdvancedUsage#User_Interaction). Also, if you do some searching on StackOverflow or Google, you can likely find the answer. Like http://stackoverflow.com/questions/8417389/how-can-i-access-logcat-file-on-device. [this](http://goo.gl/LqUtk) might also be helpful. – Reed Jan 24 '12 at 21:08