Reputation: 7193
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.
Upvotes: 4
Views: 2825
Reputation: 8488
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");
Upvotes: 1
Reputation: 18988
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.
Upvotes: 1
Reputation: 18978
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
for more detail check Developer Site.
Upvotes: 4