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
information.

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
captured
when/if my app crashes.

tia,
  mike


--~--~---------~--~----~------------~-------~--~----~



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
Manifest.

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;
try
{
        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
(mLogcatProc.getInputStream()));

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

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



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. how do i send mouse/touch event system wide

something like
Input.mi = mouseEvent;
::SendInput(1,&Input,sizeof(Input));
in windows

-- 

2. (Id android) evo bisa sampe 20 jam tanpa charging

Mantap banget, di undervolt bisa sampe 20 jam, pemakaian normal wajat,
dengan sesekali streaming sama dipake browsing

-- 
"

<<attachment: screenshot_22.png>>

3. someone please explain this error and how to get rid of it

4. Broadcast before shutting down

5. WebView

6. Scrollbar in AdapterView derived object

7. Use your Machine as ADK with libusb