Android Log.v(), Log.d(), Log.i(), Log.w(), Log.e() - When to use each one?

What are the appropriate situations to use each type of Logging? I know that perhaps it's just a little bit of semantics and perhaps it doesn't really matter, but for LogCat filtering in Android Studio and Eclipse, it would be nice to know I am using the proper methods at the appropriate times.

28.1k 22 22 gold badges 127 127 silver badges 157 157 bronze badges asked Oct 31, 2011 at 20:19 Jake Wilson Jake Wilson 90.6k 96 96 gold badges 257 257 silver badges 371 371 bronze badges Remember also the use of custom logs. They can be really useful when targeting specific scenarios. Commented Nov 16, 2020 at 13:44

7 Answers 7

Let's go in reverse order:

684 6 6 silver badges 19 19 bronze badges answered Oct 31, 2011 at 20:32 Kurtis Nusbaum Kurtis Nusbaum 30.8k 13 13 gold badges 80 80 silver badges 105 105 bronze badges

Hey buddy! I finally find myself doing some Android work at Google. And I ran into this while trying to figure out how to log things. :)

Commented Apr 29, 2014 at 21:01

I did not believe Log.wtf I even checked couple of times and laughed really out loud .. In my opinion, All APIs should have something like this within

Commented Feb 5, 2016 at 7:35

I would suggest Log.v be used in conjunction with Log.i . Use Log.i to report a successful connection, then Log.v to give more details about that connection.

Commented May 25, 2016 at 4:19 wtf Stands for "What a Terrible Failure" Commented Jun 8, 2016 at 4:34

Who named those method? That is a terrible idea. I wonder how my team would appreciate if I named my stuff with only 1 letter names. Bet they would send me to hell?

Commented Jun 13, 2019 at 17:57

The different methods are indications of priority. As you've listed them, they're going from least to most important. I think how you specifically map them to debug logs in your code depends on the component or app you're working on, as well as how Android treats them on different build flavors (eng, userdebug, and user). I have done a fair amount of work in the native daemons in Android, and this is how I do it. It may not apply directly to your app, but there may be some common ground. If my explanation sounds vague, it's because some of this is more of an art than a science. My basic rule is to be as efficient as possible, ensure you can reasonably debug your component without killing the performance of the system, and always check for errors and log them.

V - Printouts of state at different intervals, or upon any events occurring which my component processes. Also possibly very detailed printouts of the payloads of messages/events that my component receives or sends.

D - Details of minor events that occur within my component, as well as payloads of messages/events that my component receives or sends.

I - The header of any messages/events that my component receives or sends, as well as any important pieces of the payload which are critical to my component's operation.

W - Anything that happens that is unusual or suspicious, but not necessarily an error.

E - Errors, meaning things that aren't supposed to happen when things are working as they should.

The biggest mistake I see people make is that they overuse things like V, D, and I, but never use W or E. If an error is, by definition, not supposed to happen, or should only happen very rarely, then it's extremely cheap for you to log a message when it occurs. On the other hand, if every time somebody presses a key you do a Log.i(), you're abusing the shared logging resource. Of course, use common sense and be careful with error logs for things outside of your control (like network errors), or those contained in tight loops.

Maybe Bad

Log.i("I am here"); 

Good

Log.e("I shouldn't be here"); 

With all this in mind, the closer your code gets to "production ready", the more you can restrict the base logging level for your code (you need V in alpha, D in beta, I in production, or possibly even W in production). You should run through some simple use cases and view the logs to ensure that you can still mostly understand what's happening as you apply more restrictive filtering. If you run with the filter below, you should still be able to tell what your app is doing, but maybe not get all the details.

logcat -v threadtime MyApp:I *:S 
answered Oct 31, 2011 at 20:50 John Michelau John Michelau 1,201 11 11 silver badges 12 12 bronze badges

You can use LOG such as :

Log.e(String, String) (error) Log.w(String, String) (warning) Log.i(String, String) (information) Log.d(String, String) (debug) Log.v(String, String) (verbose) 
private static final String TAG = "MyActivity"; . Log.i(TAG, "MyClass.getView() — get item number " + position); 
answered Mar 27, 2018 at 3:37 Hai Nguyen Le Hai Nguyen Le 111 1 1 silver badge 2 2 bronze badges

Even though that this question was already answered I feel that there are missing examples in the answer that was answered.

Therefore I'll bring here what I wrote in a blog post "Android Log Levels"

Verbose

Is the lowest level of logging. If you want to go nuts with logging then you go with this level. I never understood when to use Verbose and when to use Debug. The difference sounded to me very arbitrary. I finally understood it once I was pointed to the source code of Android¹ “Verbose should never be compiled into an application except during development.” Now it is clear to me, whenever you are developing and want to add deletable logs that help you during the development it is useful to have the verbose level this will help you delete all these logs before you go into production.

Debug

Is for debugging purposes. This is the lowest level that should be in production. Information that is here is to help during development. Most times you’ll disable this log in production so that less information will be sent and only enable this log if you have a problem. I like to log in debug all the information that the app sends/receives from the server (take care not to log passwords. ). This is very helpful to understand if the bug lies in the server or the app. I also make logs of entering and exiting of important functions.

Info

For informational messages that highlight the progress of the application. For example, when initialising of the app is finished. Add info when the user moves between activities and fragments. Log each API call but just little information like the URL , status and the response time.

Warning

When there is a potentially harmful situation.

This log is in my experience a tricky level. When do you have a potential harmful situation? In general or that it is OK or that it is an error. I personally don’t use this level much. Examples of when I use it are usually when stuff happens several times. For example, a user has a wrong password more than 3 times. This could be because he entered the password wrongly 3 times, it could also be because there is a problem with a character that isn’t being accepted in our system. Same goes with network connection problems.

Error

Error events. The application can still continue to run after the error. This can be for example when I get a null pointer where I’m not supposed to get one. There was an error parsing the response of the server. Got an error from the server.

WTF (What a Terrible Failure)

Fatal is for severe error events that will lead the application to exit. In Android the fatal is in reality the Error level, the difference is that it also adds the fullstack.