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. Could not load CSS from local html file. Is functionloadDataWithBaseURL() has some problem or I need to call some other function.

Hi all,

Problem: css is not loaded of a HTML file [ i am using
loadDataWithBaseURL("file", new String(arry), "text/html", "utf-8", "
") from class WebView ]

What I have done:
1- Pushed test.HTML file into /sdcard
2- Made test_files folder in /sdcard (it looks like /sdcard/
test_files)
3- In folder /sdcard/test_files/ i pushed my css file (ex.css )
4- I read the test.html file into byte array and passing to function
loadDataWithBaseURL() in string format.

Its proper behavour that html file should be loaded with css
properties.
But css doesn't executes at all :( in this case.


Can anybody help me regarding this?
Why the css file is not executing at all? Is there any other way where
I can load my html file with proper css applied on.

I am giving all my code below here?

-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
test.html
-------------------------------------------------------------------------------------------------
<html>
<head>
<link rel="stylesheet" type="text/css" href="test_files/ex.css" />
</head>
<body>

<h1>This header is 36 pt</h1> <h2>This header is blue</h2> <p>This
paragraph has a left margin of 50 pixels</p>

</body>
</html>
--------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
ex.css
-------------------------------------------------------------------------------------------------
body {background-color: yellow} h1 {font-size: 36pt} h2 {color: blue}
p {margin-left: 50px}

-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
My java code
-------------------------------------------------------------------------------------------------
package com.android.LocalFileBrowsing;

import java.io.File;
import java.io.FileInputStream;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class LocalFileBrowsing extends Activity {
    @Override
    public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
          WebView webView = new WebView(this);
          setContentView(webView);
          File file = new File("/sdcard/Google.html");
          if (!file.exists())
                return;
          byte[] arry = new byte[(int) file.length()];
          try {
                FileInputStream fin = new FileInputStream(file);
                fin.read(arry);
                fin.close();
          } catch (Exception e) {
                e.printStackTrace();
          }

          webView.loadDataWithBaseURL("file", new String(arry), "text/
html", "utf-8", "Error: 404 ");
    }
}


Thanks in advance.
Ajeet
--~--~---------~--~----~------------~-------~--~----~

2. Could title bar of activity listen to click event?

This probably isn't going to be too useful -- the title bar takes advantage
of not being touchable by making itself less tall.  Trying to touch that
title bar, with the active status bar already right above it, would be not
too easy.  So if you do want to have a touchable title bar, you probably
want yours to be taller than the normal title bar, so you might just want to
make your own custom title bar.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

3. java.lang.reflect.InvocationTargetException during calling a function of another application at runtime

4. How to use two different icon in two different themes

5. Question regarding adding a view that can overlap other views in the layout/activity.

6. AudioFormat class's workaround

7. Calendar application still missing from emulator