How to capture some/all of the log file from an application?

by Mike Collins » Sat, 14 Mar 2009 02:48:21 GMT

Sponsored Links
 I know how to use adb's logcat to capture the log information.
I know how to use logcat inside an adb shell to display the log

Is it possible to do this from my application on the phone?

I'm trying to get a bit more context than just the call stack
when/if my app crashes.



How to capture some/all of the log file from an application?

by Carter » Sat, 14 Mar 2009 12:26:59 GMT

 You must request the android.permission.READ_LOGS in your Android

Then you can run the logcat from the command line on the phone, and
just get a dump of the output.  I recommend filtering the output for
both AndroidRuntime with the error level only (to gather exceptions
that crashed your app) as well as all messages from your app's log
tag.  See below:

Process mLogcatProc = null;
BufferedReader reader = null;
        mLogcatProc = Runtime.getRuntime().exec(new String[]
                {"logcat", "-d", "AndroidRuntime:E [Your Log Tag Here]:V *:S" 
}); //
$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        reader = new BufferedReader(new InputStreamReader

        String line;
        final StringBuilder log = new StringBuilder();
        String separator = System.getProperty("line.separator"); //$NON-
        while ((line = reader.readLine()) != null)

        // do whatever you want with the log.  I'd recommend using Intents to
create an email
catch (IOException e)
        if (reader != null)
                catch (IOException e)


Sponsored Links

Other Threads

1. webservices-android-ksoap2 ? can i find the answer in this group

hello guys ,

i am new to webservices , my friend has built a webservice that i need to
use in order to complete my project
i have used this code snippet for the purpose of using this webservice , but
it always keep giving me and exception
when i reach this call :, envelope);

please help me in this ... !!

here is my code

import org.ksoap2.SoapEnvelope;



2. Join an app test group?

I am interested in forming an application test group for beta android
apps.  Testers would volunteer, developers could post their app for
review by the test group.

This would benefit the developer - who gets feedback to make their app
better; and the community - which gets a quality filter.

Android is important.  It serves the ideal of open development and
open market.  We can support its growth by creating a place where apps
can be reviewed prior to release.  The feedback would range from
technical (bugs, interface) to feature suggestions to market potential
(price, value).

If you would be interested in participating - respond.  If there is
enough interest here, I will form a group and we can move forward..




3. How to incorporate external library for android JNI project for a device

4. Camera Force Closed 9/10 of the times

5. Assets not appearing in emulator/G1

6. packaging android-specific application to reusable jar file

7. horizontal/vertical finger swipe...