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. How to order T-Mobile G1?

T-Mobile G1---The First Android Phone has announced,I am very e{*filter*}d.
I don't know how to order the android phone,can somebody talk about
such related things in  details?
1) the price is $179,   but   plus taxes and fees; two-year agreement
requiredd,how about ethe
actual price? how about the price for the developers outside USA?
2)i am not t-mobile member from china,I use china mobile network,how
to order and use?

Thanks in advane.
Android DotPhone Team


2. Emulator Skins for HTC Dream / T-Mobile G1

Hello Android fans and developers.

I just finished building the first HTC Dream/T-Mobile G1 skins for the
Android emulator and would like to share them with you. Right now I
have done the black version of the phone in portrait as well as in
landscape mode. They are tested to work with the latest Android SDK
version 1.0r1 (they also work with the 0.9beta).

You can get them here: (preview
screenshots available)

I hope you like them and can put them to good use.


3. Access to GSM Modem

4. IPC (by domain socket) between Android's LocalSocket and Linux kernel's PF_LOCAL socket

5. Can AlertDialog not dismiss after click buttons?

6. Physical Device Keypad Events.

7. Error - Unable to create the selected preference page.