Not able to capture log from robotium

685 views
Skip to first unread message

Bharathi raja

unread,
Jun 29, 2011, 5:56:34 AM6/29/11
to Robotium Developers
Hi All,

I used below code to capture log but not capturing, even in manifest
file i added read log permission.

private Process process;
try{
File dir = Environment.geExternalStorageDirectory();
if(process!=null)
process.destroy();
File logFiles = new File(dir.toString()+"/LogFile.txt");
if(logFile.exists()==true)
logFile.delete();
process=Runtime.getRuntime().exec("/system/bin/logcat -c");
process=Runtime.getRuntime().exec("/system/bin/logcat -f "+logFile);
}
catch(Exception e){
}

log file created without any log on sdcard.

Please help me if anyone know the reason
whether we can capture log from robotium????????????

Regards,
Bharathiraja R

Yahor Paulavets

unread,
Jun 29, 2011, 8:17:56 AM6/29/11
to robotium-...@googlegroups.com
Hello,

I have tried to do following on device:

# su system <--- switch to the System user (because your app acts as a System user with its permissions)
$ /system/bin/logcat -f /media/1.txt <----- run command for logging into the text file
Unable to open log device '/dev/log/main': Permission denied  <------- got an error.

I bet you can get same error if you read your second process's error stream.

I think,  we are not allowed to read logcat output without root permissions.

Or your application has root access?

Best regards,
Yahor



--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To post to this group, send email to robotium-...@googlegroups.com.
To unsubscribe from this group, send email to robotium-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotium-developers?hl=en.


Erik Hansen

unread,
Jun 30, 2011, 2:46:57 AM6/30/11
to robotium-...@googlegroups.com
Hi

For capturing LogCat were using the following at LessPainful.com. 
Instead of trying to capture it from the phone we are using adb to capture it from outside of the phone.

1) Before stating the test run from a terminal: "adb logcat -c". This will clear the log so you only capture logs related to the test run
2) Then run " logcat -v time >output.log&"
3) After test has stop running kill the process started in step 2.

/Erik



Bharathi raja

unread,
Jun 29, 2011, 11:17:27 AM6/29/11
to robotium-...@googlegroups.com
i am using root access device
same code work when i capture log from own android application
but not from robotium

Regards,
Bharathiraja R

Yahor Paulavets

unread,
Jun 30, 2011, 4:47:18 AM6/30/11
to robotium-...@googlegroups.com
Hello,

Also, if you have all permissions in your app, you are able to read logcat output inside your application,
just get Output Stream and write it at any location you like.

Best regards,
Yahor

--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.

Yahor Paulavets

unread,
Jun 30, 2011, 5:01:33 AM6/30/11
to robotium-...@googlegroups.com
Hello,

Did you try to write file into some other location?

 try {
            String cmd = "logcat";
            Log.i("############## **************", "CMD: " + cmd);
            Process log = Runtime.getRuntime().exec(cmd);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(log =.getInputStream()));

            String line = null;
            while ((line = in.readLine()) != null) {
                Log.i("#####", line);
            }

            Log.i("##########", "**************************************");
        } catch (Exception ex) {
            ex.printStackTrace();
        }

Try to read logcat output first, if it is possible, you can add your own file writing logic.

Over adb you have root access to your device, but from application, you do not have root access.
So possibly, logcat just refuses to start due to low privileges.

Try to play with InputStream and ErrorStream to understand what is really happened.

Best regards,
Yahor

Yahor Paulavets

unread,
Jun 30, 2011, 5:02:36 AM6/30/11
to robotium-...@googlegroups.com
correct snippet:


try {
            String cmd = "logcat";
            Log.i("############## **************", "CMD: " + cmd);
            Process log = Runtime.getRuntime().exec(cmd);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(log.getInputStream()));

Renas

unread,
Apr 23, 2013, 1:36:57 AM4/23/13
to robotium-...@googlegroups.com
Hi,

Use solo.waitForLogMessage(String logMessage)

/Renas




On Tue, Apr 23, 2013 at 7:23 AM, Ukai <mayu.k...@gmail.com> wrote:


I tried the suggested code below. It partially executed the code(ie, the while loop) and displayed a heap error after 5 mins.  And eventually my eclipse froze.  I don't have a rooted phone. I just want to verify certain strings in logcat.  Could anyone advise me?  Is there a simple way to check logcat?


try {
            String cmd = "logcat";
            Log.i("############## **************", "CMD: " + cmd);
            Process log = Runtime.getRuntime().exec(cmd);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(log.getInputStream()));

            String line = null;
            while ((line = in.readLine()) != null) {
                Log.i("#####", line);
            }

            Log.i("##########", "**************************************");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
--
You received this message because you are subscribed to the Google Groups "Robotium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotium-develo...@googlegroups.com.

To post to this group, send email to robotium-...@googlegroups.com.

Mayu Kataoka

unread,
Apr 23, 2013, 1:53:47 AM4/23/13
to robotium-...@googlegroups.com
Thank you, Renas.  This is exactly what I was looking for.


--
You received this message because you are subscribed to a topic in the Google Groups "Robotium Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robotium-developers/Js1sB2qFwC8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to robotium-develo...@googlegroups.com.

Yahor Paulavets

unread,
May 6, 2013, 10:26:46 AM5/6/13
to robotium-...@googlegroups.com
Hi everybody,

Please advise how to clear logcat before test start? 

Does robotium provide method for this? :)

Thank you in advance.

Best regards,
Yahor


Yahor Paulavets

unread,
May 6, 2013, 10:31:30 AM5/6/13
to robotium-...@googlegroups.com
Or only one way is to execute via Process logcat -c?

Best regards,
Yahor
Reply all
Reply to author
Forward
0 new messages