How do i retrieve the error logs of my application from device (and send them over the internet to a server)?
- 2to clarify - do you mean collect log entries (generated by your app) from other peoples' phones and send to your web server programmatically ?Someone Somewhere– Someone Somewhere2011-01-24 05:44:09 +00:00Commented Jan 24, 2011 at 5:44
- Ideally, you could make a type of error handling class that is instantiates an object when an error is generated. Once the object is created, it connects and send that log to your webserver.Anthony Forloney– Anthony Forloney2011-01-24 05:50:07 +00:00Commented Jan 24, 2011 at 5:50
2 Answers
(Assuming you are using log framework from android.util.Log package.)
You can start "logcat" process with specific parameters from within your process. It will dump last 16k of logs (16k - is default for my phone, it can be different on other phones).
Here is an example of command line that dumps all logs: logcat -d -f /mnt/sdcard/log-dump.txt
Another example that dumps errors from all applications: logcat -d -f /mnt/sdcard/err-dump.txt *:e
You'll need to launch the process from within your application programatically. And then process log-dump.txt/err-dump.txt in the way you want.
You also may want to monitor logs longer then those default 16k can allow you. For this you'll need to start logcat without -d parameter. If this is done, logcat process will write logs to file for as long as you want. When you are done just kill logcat process.
In any case you can look & test manually logcat using adb logcat <params> from you computer.
Comments
I think you need to implement the try_catch block.
try { } catch(Exception e) { Log.e("Exception found ",e.getMessage); // post the exception message to your server } This way you can send the error log messages to the server.