Redirect ADB logcat output to a file

When developing with Android Studio, you often encounter problems with logCat’s logs not being displayed. For example, when the app crashes, the logcat log flashes. When the Activity restarts, the logcat log is the new log, and it cannot display the log from the crash, which is very painful.

So is there a good way to see the log? If you type adb logcat in the terminal, you can see the same log as logcat.

Adb logcat in terminal

tinytongtongdeMacBook-Pro% adb logcat
Copy the code

But the logs are unfiltered and look like a lot of effort.

Filter logs related to specific projects

In double quotes are the filter related strings, and here I’m writing my own appId.

tinytongtongdeMacBook-Pro% adb logcat -d | grep "com.tiny.tongtong"
Copy the code

Redirect logcat output to a file

tinytongtongdeMacBook-Pro% adb logcat -d > logcat.log
Copy the code

This command overwrites the logcat.log file each time it is written. If you want to append to it, go to > Cache >>.

To summarize, if we want to save application-related logs to a file, the command is as follows:

tinytongtongdeMacBook-Pro% adb logcat -d | grep "com.tiny.tongtong" > logcat.log
Copy the code

Matters needing attention

This works only if you don’t execute the adG shell -c command to clear your error message after it is output to logcat, and you don’t click the clear button in the upper left corner of the Logcat view in AS.

good luck!

Reference:

Logcat command line tool

Save LogCat To A Text File