The basics of using logcat in Android development

I'm just starting Android, and I don't understand how to use this logcat thing.

I am working on an emulator, but I will probably work on a real device in the future. One of the programs tested ( VIEW HERE ) freezes when it starts, and other users recommend looking at the logarithm. But logcat on my computer continues to show new text and scrolls. I'm not sure how to look for anything in this whole mess. Sometimes it keeps scrolling when I don’t even test my program.

Does it show things, if I do anything at all in the emulator? The emulator is already so slow that it is difficult to determine which event on the emulator triggers which message.

Also, for a beginner, what level of verbosity on the logarithm is enough? Switching to an assertion does not show anything (which is probably logical since I have no assertions), so I assumed that the error was probably the least complicated, but even then there were too many messages in the log to process.

What is the minimum level of detail that I need to set, and is there any sample program that allows me to check which event in the code generates which view if the message is in logcat? (I use logcat in the IDE)

--- EDIT ---

I see logcat has messages like

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 information mode, and in the detailed version mode there is even more incomprehensible text, so I did not include it. It seems that he can’t find the file containing the sound effect that will play when you press the back button that it displays in the log. How to delete such unnecessary messages related to the phone OS user interface and display messages related to the program I am testing and what caused it to hang up before even the onCreate () call is called in the code? I want to be able to do this from the IDE at the moment.

+4
source share
3 answers

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. Do not forget that when you make a call, for example

 Log.e(TAG, "index=" + i); 

Use Log.e(); because it shows you a red color , you can easily identify the error in all logs


you can also use flitter logs in eclipse below.

enter image description here

enter image description here

for a more detailed check Developer site .

+4
source
 adb -d logcat <your package name>:<log level> *:S 

-d is the actual device, and -e is the emulator. If more than 1 emulator works, you can use -s emulator-<emulator number> (for example, -s emulator-5558 )

Example: adb -d logcat com.example.example:I *:S

Or, if you use System.out.print to send messages to the log, you can use adb -d logcat System.out:I *:S to display only calls to System.out .

You can find all levels of the magazine and additional information 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");

+1
source

What I do when working with the application with the problem is to switch to ERROR mode in logcat, and also add a filter for my application package name, for example. com.something.blah . Thus, I have ever seen error messages related to my application.

Of course, there are times when this is not enough, but by the time you need more information, you will be comfortable working with logcat :)

For manual logging (using Log.* ), A very unique tab (something like ThisIsAVeryUniqueTag1234 ) can save a lot of time. Just filter this tag and these should be the only posts you see. See Log for complete information on how to use tags and manual logging.

+1
source

Source: https://habr.com/ru/post/1496711/


All Articles