Android Error Logging
How do 开发者_运维百科i retrieve the error logs of my application from device (and send them over the internet to a server)?
(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.
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.
精彩评论