why does logcat drain messages - android

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:
Disable the auto scrolling feature. Click on the "Scroll Lock" button to disable this.
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.

Related

Adb read contents of an Alert Dialog

i have an android phone connected to my pc, using ADB i can run some commands to the device and get output, now am in a situation where i want ADB to read the contents of an Alert dialog. i have been Googling all day but couldn't find anyone on the internet talking about it.
I need an adb command that can read the message content in that dialog for example
UPDATE: I know some people might tell me to add code for logs in my app, however am talking about the system dialogs, not dialogs from my app, of course i can add log tags in my app that way i can get them but what i want here is the dialogs from the android-system.
If you're running your own app or in a position to change the source of the one you're running, you could find where the message gets drawn and log it using Log.i("YourTag", "TheMessage"). The .i stands for info and there's other log classes you can use (d, e, w, v).
You can then read logs with adb logcat, and filter them if you want by running adb logcat YourTag:* *:S. This tells logcat to show all messages tagged YourTag (* instead of, for example, .i to show info messages only), and silence everything else.

Strange logcat filter behaviour

Sometimes I am on the lookout for specific logcat messages for debugging purposes and its critical to see exactly when they appear. I then make a logcat filter (call it xx) in eclipse ready to spot the critical message. I then highlight the xx filter and run my app and look out for my message - nothing appears in my xx filer view - but I notice increasing numbers win brackets next to the "All messages (no filters)". If I then click on the All messages thing and then go back to xx then hey-presto my messages are visible. Its almost as if eclipse is determined never to let me see these messages as they arrive. Is there anything I can do about this?
I've found that part of the eclipse plugin very unreliable, especially if there are a high volume of log messages it is prone to making the whole window slow / freeze.
Personally, I tend to run logcat in a shell, sometimes piped into grep
tee can also be useful, to write a copy to disk for later examination.
Make sure that logcat isn't paused.

Dalvik Debug Monitor not showing all logs

In my Dalvik Debug Monitor new log messages which have different tag than previous log message are displaying after erasing all previous log messages. That means log is clearing itself all the time and only showing a few lines. What will i do to view all Log messages??
This happens a lot to me too. As far as I know there's no easy way around it but have a look at this python script which I modified (for full disclosure this is the original colored logcat script
- I changed the formatting and tweaked it a bit)
or you could just use the command line:
adb lolcat
or if you're interested in a specific tag, and using unix (or cygwin as I noticed you're on the PC):
adb lolcat | grep TextToFind
P.S. yes I know I'm using lolcat, instead of logcat - both will work. lolcat is just for the lulz
* EDIT *
You can also use logcat filtering to get the data you want from logcat. For example I ususally use this combination:
adb logcat MyAppTag:* *:E
this gives me all the logs which has a tag of MyAppTag and all other error and fatal messages. This is, imo, a better way of doing it than using grep.

Android Dev: Logcat in Eclipse - can't restrict output to V/D/I/E?

I'm using Logcat in Eclipse. I've been unable to find documentation online telling me as such, but presume that the V, D, I, E etc. buttons when clicked should restrict Logcat output to that pipeline? No matter which I select, every logcat output is spewed out, and it's making debugging nigh on impossible.
Can someone please tell me how to display only Debug output, i.e. Log.d(..) prints? I don't think this is possible using a filter, since I've tried creating one with log level 'Debug' and an empty tag and pid field, yet this simply prints all log outputs again.
Many thanks!
UPDATE
So, thanks to Aleadam's link below, I'm now aware that V/D/E/ etc. are 'priority levels' and include those priorities lower than themselves. It doesn't seem possible to restrict to only D(ebug) output, but at least I know how to restrict to D,V since V(erbose) is the only priority level lower than Debug:
adb logcat *:W
Of course, this must be done via the command line, so I'm now going to figure out how to employ the same strategy in Eclipse. The buttons really aren't working for me, I've no idea why, but it's frustrating!
Many thanks for all the information you've posted, guys.
Those buttons should work in the manner you're describing so long as they were logged with the appropriate API call in the Log class. http://developer.android.com/reference/android/util/Log.html
Regexes/wildcards do not work. There's a bug I requested from almost a year ago. http://code.google.com/p/android/issues/detail?id=11580&can=4&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
adb logcat *:D will not show only debug, but everything with debug priority or higher.
For example, adb logcat *:E > err.log will save errors only.
For many options, check "Filtering Log Output" in here: http://developer.android.com/guide/developing/tools/adb.html#logcat
If you're running under linux use grep. If you're on windows, use the shell: (e.g. adb shell "logcat |grep 'D\/'")
Filtering works on my system but I specify a Log Tag. This then creates a new button next to Log. So for Log Tag "QPR" I see [Log][QPR] buttons and when I press on [QPR] I only see logging that has been tagged as "QPR" as in Log.d(TAG,"onCreate",e);
At least on my system if I click on [Log] (E) I only get errors.
Hope that helps,
JAL

Logcat in eclipse keeps auto clearing

until recently my logcat has been fine but all of the sudden whenever i try to view it in eclipse it just keeps clearing itself whenever anything is displayed making it impossible to read. viewing it in the adb works but I never bother with that since it is just such a pain to read and find anything you are looking for.
is there a way to fix this problem?
The Logcat messages were simple getting cleared because the buffer had run out of space (receiving too many new messages), which is a simple setting change in Eclipse.
To fix, go to Window > Preferences > Android > LogCat
and increase the limit for "Maximum number of LogCat messages to buffer". Set it to 0 for unlimited size, or a really big number. But keep in mind, anything below 10000 fills up real fast.
Been answered already:
Eclipse Android - Logcat Clearing too Fast
It will show one line before erasing it to show the next one? Just click the verbose button again.
There's a workaround for this bug. Click active mode button (usually verbose), choose another device from device list and choose previous device again. It will restore all logcat messages.
LogCat is really annoying for this. In Ubuntu, I found the following works really well:
Open a terminal and type adb logcat | grep MYINFO
This will only show adb messages filtered by the MYINFO string.
So, you can code something like:
Log.v("MYINFO", "x" + x_value + ", etc...");
This is such a relief to use. A life saver! See this for more info.
You may find sometimes the logcat buffer repeats previous logs on starting again. To overcome this, type
adb logcat -c

Categories

Resources