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.
Related
I am using Monkeyrunner (automation) to test an app on an Android device (Samsung S2), and since it does not allow me to see image patterns on the screen, I have to rely on the adb logcat (using Windows) to look for specific messages in order to know when the next page has loaded for my automation script.
And in order to look for specific (unique) messages in the logcat, for my monkeyrunner script, I have to CLEAR out ALL the adb logs, then perform the search.
Is there a way to clear out only the line(s) that match a specific tag, message, text, or whatever(!), within the logcat log? Instead of clearing out everything?
Does the command line adb functionality allow you to clear specific lines, or is it an all or nothing kinda thing?
Clearing out all the logcat longs works, but it would be nice to ONLY clear out certain messages so that if/when there is an app crash, or some event where I need details for troubleshooting, I can see all the logs leading up to the crash (or significant event). Because if everything is cleared out, there is no way for me to see the logcat logs to troubleshoot whatever.
::: MORE INFORMATION :::
Here is the function I currently use to clear out all the logs.
def clearAdb():
p = subprocess.Popen("adb logcat -v time", shell=True, cwd="C:\Users\<USERNAME>AppData\Local\Android\sdk\platform-tools", stdout=subprocess.PIPE)
subprocess.Popen("adb logcat -c", shell=True, cwd="C:\Users\<USERNAME>AppData\Local\Android\sdk\platform-tools", stdout=subprocess.PIPE)
print("::: ADB cleared :::")
..and here's an example of how I am looking for the logcat log. This adb function waits indefinitely for a specific adb message, and process when seen.
def adb(message):
p = subprocess.Popen("adb logcat -v time", shell=True, cwd="C:\Users\<USERNAME>\AppData\Local\Android\sdk\platform-tools", stdout=subprocess.PIPE)
for line in p.stdout:
if message in line:
print("Got 'em")
break
else:
continue
...and this is how I currently use the functions together...
clearAdb()
adb("identifyGamePackage. com.tfg.nameofapplication")
To limit logcat output to messages which happened after certain moment you do not have to clear the log. Instead use logcat -T <timestamp> filter. Supported timestamp formats depend on the Android version - see -T paragraph in logcat -h output.
I am just starting Android and I don't understand how to use this logcat thing.
I am working on the emulator but will probably be working on a real device in the future as well. One of the programs that was testing (SEE HERE) hangs up when it starts and other users suggested I look at the logcat. But the logcat in my computer keeps on displaying new text and scrolling up. I am not sure how to look for anything in all that mess. Sometimes it keeps scrolling when I am not even testing my program.
Does it show things if I do anything at all in the emulator? The emulator is already so slow that it's hard to figure out which event on the emulator is causing which message.
Also, for a beginner, what level of verbosity is enough on the logcat? Going to assert doesn't show anything (which is probably logical as I don't have assertions enabled) and so I assumed Error was probably the least verbose mode, but even then the log has too many messages to handle.
What is the minimum verbosity level that I need to set it to, and is there any sample program out there that lets me test what kind of event in the code produces what kind if message in the logcat? (I am using logcat in the IDE)
--- EDIT ---
I see that the logcat has messages such as these
08-12 08:24:26.699: I/Choreographer(528): Skipped 57 frames! The application may be doing too much work on its main thread.
08-12 08:25:02.550: I/Choreographer(528): Skipped 33 frames! The application may be doing too much work on its main thread.
08-12 08:25:07.950: I/Choreographer(528): Skipped 37 frames! The application may be doing too much work on its main thread.
08-12 08:25:08.022: E/SoundPool(287): error loading /system/media/audio/ui/Effect_Tick.ogg
08-12 08:25:08.022: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
08-12 08:25:08.022: E/SoundPool(287): error loading /system/media/audio/ui/Effect_Tick.ogg
08-12 08:25:08.022: W/AudioService(287): Soundpool could not load file: /system/media/audio/ui/Effect_Tick.ogg
This is in the Info mode, and the verbose mode has even more incomprehensible text so I didn't include it. It looks like it cannot find the file containing the sound effect to be played when the back button is pressed, which it is displaying on the log. How do I remove such unnecessary messages related to the phones OS user interface and only display messages related to the program I am testing and what's causing it to hang up before even onCreate() is called in the code? I want to be able to do this from the IDE for now.
Log.v() - VERBOSE
Log.d() - DEBUG
Log.i() - INFO
Log.w() - WARN
Log.e() - ERROR
Tip: A good convention is to declare a TAG constant in your class:
private static final String TAG = "MyActivity";
Tip: Don't forget that when you make a call like
Log.e(TAG, "index=" + i);
Use Log.e(); because it show you in red color you can easily identify error in all log
you can also use flitter Logs in eclipse check below.
for more detail check Developer Site.
What I do when working on an app with a problem is to switch to ERROR mode in the logcat and also add a filter for my application's package name, ex. com.something.blah. This way I only ever see error messages related to my app.
Of course there are times when this is not enough info, but by the time you need more info you should be comfortable working with the logcat :)
For manual logging (using Log.*) a very unique tab (something like ThisIsAVeryUniqueTag1234) can save a lot of time. Just filter on this tag and it should be the only messages you see. See Log for full info on how to use tags and manual logging.
adb -d logcat <your package name>:<log level> *:S
-d denotes an actual device and -e denotes an emulator. If there are more than 1 emulators running you can use -s emulator-<emulator number> (eg, -s emulator-5558)
Example: adb -d logcat com.example.example:I *:S
Or if you are using System.out.print to send messages to the log you can use adb -d logcat System.out:I *:S to show only calls to System.out.
You can find all the log levels and more info here: http://developer.android.com/guide/developing/tools/adb.html#logcat
You should use Log.<log level>(TAG, message) in your code where the tag can be anything but I always use the package name.
Example:
Log.i("com.example.example", "message");
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.
I have Log.d to log some info inside the the source files.
1)Where do you see the output of that Log.d statement? Logcat has way too many process and kernel operations listed just junked up the whole place. I don't need to know all those internal system operations. I only need to list the Log.d statement.
You can specify a filter as described in the 'adb logcat' help output. But you need to also silence the things you are not interested in. For instance, if you specified the Tag as 'MyApp' you can just have logcat dump the MyApp lines using:
adb logcat 'MyApp:v,*:s' which silences everything (*:s) and displays anything tagged with 'MyApp' that is verbose and above. For debug and above use 'MyApp:d' instead.
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