简体   繁体   中英

why does logcat drain messages

When I test my android app, I log messages that show up on LogCat. But the messages drain out the top of the window quickly making it impossible to read them quickly enough.

How can I stop this?

There's a scroll lock in the logcat window that you can use to pause the printout for a moment.

To get complete logcat messages, you can redirect them to a file:

adb logcat >& output.log

It depends somewhat on what you mean by "drain". If the problem is simply that messages are scrolling by too fast and you need to stop auto-scrolling to the bottom, you can pause this feature in the IDE (or in DDMS/Monitor). HOW you pause it depends on your IDE, in IntelliJ you can just click somewhere in the log output to place a cursor, and in Eclipse there is a button above the logcat window to pause the output scrolling (don't forget to turn it back on or you won't see new messages).

However, if your problem is that so much data is being logged that you cannot scroll up to see what you need even if scrolling is paused, you need to log less. This is because the Android logcat driver is a fixed-size 64KB circular memory buffer. So if you log enough data, it will begin to overwrite the older entries in the log and they will be gone before you've had a chance to read them.

There are some methods:

  1. Disable the auto scrolling feature. Click on the "Scroll Lock" button to disable this.
  2. Use the command line tools. Run "adb logcat | less" and you can navigate for the results. You can also run "adb logcat > logcat.txt" and inspect logcat.txt after that.

Why don't you filter the logcat, so it shows the things your are most interested in.

You can display only the tags you are interested in with the following syntax (using the adb tool from the command line - also available in the logcat view in Eclipse):

adb logcat TAGTOSHOW:* TAGTOSHOW2:* *:s

You can include as many TAG combinations as you want. Don't forget the *.s which silences all the rest.

I prefer teeing to a file:

adb logcat | tee foo.log | grep "YOUR_TAG_OF_INTEREST"

This way you get whatever you think you're looking for in your terminal window, but if you need to look at the full logs you have them saved off in a file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM