Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect logcat output?

Tags:

android

logcat

Is there a way to redirect the logcat's output towards an InputStream or something like that? I'm thinking of something in the lines of how you can redirect the stderr in C. I want to do it so its redirected when my app starts and everything that happends get dumped to a file.

like image 846
Moises Jimenez Avatar asked Oct 22 '12 07:10

Moises Jimenez


People also ask

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.

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.

Which class do we use to send some output to Logcat?

The Log class Log is a logging class that you can utilize in your code to print out messages to the LogCat. Common logging methods include: v(String, String) (verbose) d(String, String) (debug)


2 Answers

If you can connect the device for debugging, you can this from the command line

$ adb logcat > textfile.txt
like image 174
spatulamania Avatar answered Nov 02 '22 11:11

spatulamania


The easiest way I found is to use System.setErr. I allows you to easily redirect the error output to a file.

Example:

System.setErr(new PrintStream(new File("<file_path>"))
like image 21
Moises Jimenez Avatar answered Nov 02 '22 10:11

Moises Jimenez