Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch LogCat programmatically or export it to file?

Tags:

android

I want to filter a logcat

String myCommand="logcat -f /sdcard/output.txt"; //no filters, keep writing  
myCommand="logcat -d -f /sdcard/output.txt"; //no filters, just a dump

Working fine for me but not for mytag .

I am also using the code:

String myCommand="logcat myTag *:S"; //the equivalent of logcat -s myTag  
myCommand="logcat -s myTag:D";   
myCommand="logcat -s myTag:E myTag2:D";  
myCommand="logcat myTag:E myTag2:D";  

But it returns empty file.

like image 611
Amit_android Avatar asked May 22 '14 13:05

Amit_android


People also ask

How do I export from Logcat?

adb logcat –d > filename.txt This command will extract the logcat information from the connected device and redirects the output to a file on the PC. The option –d will take care that the output will stop when all output is flushed.

How do I send Logcat?

Tap the ellipses, and select “send” to email the log as an attached text file along with general device information. That's it! Your Logcat has been successfully captured and sent to Professor Oak.

What is Logcat output?

Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class. This page is about the command-line logcat tool, but you can also view log messages from the Logcat window in Android Studio.


2 Answers

try {
   File filename = new File(Environment.getExternalStorageDirectory()+"/gphoto4.html"); 
        filename.createNewFile(); 
        String cmd = "logcat -d -f "+filename.getAbsolutePath();
        Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

also use

String cmd = "logcat -v time -r 100 -f <filename> [TAG]:I [MyApp]:D *:S";
Runtime.getRuntime().exec(cmd);


-v -> Sets the output format for log messages.
-r -> for specifying the size of file.
-f -> file to which you want to write the logs.
[TAG] -> Tag of your application's log.
[MyApp] -> Your application name.
like image 163
Robert P Avatar answered Oct 05 '22 14:10

Robert P


File filename = new File(Environment.getExternalStorageDirectory()+"/mylog.log"); 
filename.createNewFile(); 
String cmd = "logcat -d -f"+filename.getAbsolutePath();
Runtime.getRuntime().exec(cmd);

it works for me. but for all logcat output not for special tag(mytag).

like image 36
Amit_android Avatar answered Oct 05 '22 15:10

Amit_android