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");
Related
What's the difference between Logcat and Run in Android-Studio?
Logcat has filter-options. Beside that I don't get which specific purpose each serve.
In how far do the messages differ, which become printed to each console?
When do I use which console?
Personally,Logcat is more useful for debugging and being aware of what is going on while the app is running. You set the type of the log and set tags to them, by this way you can easily filter logs. This gives you much more clear picture in terms of logging.it stated in this article
Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class.
Also, it is stated that (in the same article)
The priority is one of the following character values, ordered from lowest to highest priority:
V: Verbose (lowest priority)
D: Debug
I: Info
W: Warning
E: Error
F: Fatal
S: Silent (highest priority, on which nothing is ever printed)
each one of these shows the logs from their priority to highest one . Verbose, for instance, will print all the logs but if you switch to error , logcat only shows error and fatal logs.
Additionally, if you set a tag filter it will only shows the logs that is tagged with that "tag", of course while keeping the priority filter. For instance
Log.e("tag1","message_1");
Log.e("tag2","message_2");
Assume you have filter the tags with "tag1". The logcat will print "message_1".
Similarly
Log.e("tag1","message_1");
Log.i("tag1","message_2");
Again, assume that you have filter tags by "tag1" and priorities with Error.Then, the logcat will show only "message_1".
For the run tool also shows logs , prints (println etc.) but in comparison with the logcat it will show a lot more stuff (logs, prints (println etc. and phone related informations).
apart from your logs other logs that comes from libraries and phone itself also are shown in the run tool. So it hard to find your own logs.
Run will be useful when the phone and library related information logs needed.(for instance when the phone misses/drop frames it will be printed in run)
Logcat will be useful for your own logs.When you are trying to understand what is going on while the app runs etc..
I have noticed a big difference between the run and the logcat while using avd emulators. I had a deceiving crash on my app, only while I was using the emulators .
every time there was a crash , the logs before the crash were disappearing from the logcat , and I couldn't understand if I see the logs related to the crash. after a week of trying to find a library that prints the logs to a file I found out that everything is printed in the run tab, so I don't need that.
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 a problem with logcat output of my app:
Normally logging to logcat works. But at some times my app's output seems to be entirely removed from the logcat output. Though i can prove that the app logged, there is not a single line in logcat.
When does this happen:
I shedule my app to wakeup at midnight by a BroadcastReceiver starting a Service. The app wakes up and creates a logfile, writes to that file and to logcat in parallel by calling a function which writes to both. The logfile contains 3 lines written. (and then the app somehow dies.) At least these 3 lines have been also logged to logcat.
Next day i display all logcat messages, which encloses midnight. Not a single line logged for my app.
I think Android has purged my App from memory and at midnight it is loaded again (and crashes because it is not initialized properly). But why is there no logcat output?
thanks for your hint.
Logcat has a size limit. Once this limit is reached, older messages are purged to make room for the new ones coming in. It's not that Logcat is removing your app's messages specifically, it's that in the course of running over night there are so many other messages going to Logcat that yours are being removed.
To see the buffer size on your specific device, plug it in and execute the following command in a shell window:
adb logcat -g
If you need to collect log messages at a time where you can't physically be looking at the output window, you're doing the right thing by logging to a file. I do something similar where I'll set a global flag on the build that tells it whether to log normally or output to a local file on my phone.
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.
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.