1

I am a novice to the Android Studio and working on one group project.I am trying to log some variable values to logging. When I use Log.e values are properly logged. While when I use Log.w or Log.v nothing gets printed. Here I am switching from logcat from error to verbose and to warning as I am using Log but still can't see anything printed.I previously used Toast but heard that using it might make my app slow and using Log.e everywhere is not a good practice.So how to print logs of lower priority?

I tried referring following resources but didn't find anything that could help me enabling logging for lower priority Logs, Just got the info that for some reason lower priority logs are disabled.

  1. https://developer.android.com/reference/android/util/Log.html
  2. Android Log.v(), Log.d(), Log.i(), Log.w(), Log.e() - When to use each one?

Thank you in advance.

Mandar Sadye
  • 689
  • 2
  • 9
  • 30

1 Answers1

1

All logs are always default enabled.

I think you are viewing logs in error view.

Check

  1. You are viewing logs in Verbose
  2. Your filter is set to selected app.
  3. You have selected your app not other app. (where in below image no debuggable process is written)

enter image description here

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

Log.e: This is for when bad stuff happens. Use this tag in places like inside a catch statement. You know that an error has occurred and therefore you're logging an error.

Log.w: Use this when you suspect something shady is going on. You may not be completely in full on error mode, but maybe you recovered from some unexpected behavior. Basically, use this to log stuff you didn't expect to happen but isn't necessarily an error. Kind of like a "hey, this happened, and it's weird, we should look into it."

Log.i: Use this to post useful information to the log. For example: that you have successfully connected to a server. Basically use it to report successes.

Log.d: Use this for debugging purposes. If you want to print out a bunch of messages so you can log the exact flow of your program, use this. If you want to keep a log of variable values, use this.

Log.v: Use this when you want to go absolutely nuts with your logging. If for some reason you've decided to log every little thing in a particular part of your app, use the Log.v tag.

Explanation by link Kurtis Nusbaum

Update:

If above things does not work then you are facing an device setting issue. Some mobiles have set default log level to DEBUG or ERROR. Allow logging from phone setting.

You can check if log is loggable by Log.isLoggable()

Check

Settings -> Accessibility -> Developer options -> advanced logging->set "Allow all"

or

Settings->Accessibility - > Developer Options -> Performance optimization -> Advanced logging -> set "Allow all"

or for other phone search in "developers options": option "logging" and set "all".

  • also you can use Log.wtf when your Log.d is not working.
  • try restarting android studio also
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • I am using the option "No filter" in place of "Show only selected applications".After entering tag I am switching from verbose to error to the warning and so on to see if the log is printed but can't find.Also, I am getting package name in place of the "No debugger". Also, regex is ticked.I don't know what I am doing wrong but it seems that no one asked this question implying this issue is not common.As I said only error logs are displayed.So is there anything more that you can suggest.For now I am using Log.e for all logs – Mandar Sadye Apr 13 '18 at 18:29
  • Updated my answer, check if this is your mobile issue. – Khemraj Sharma Apr 13 '18 at 18:47
  • Advanced logging didn't work but Log.wtf is working.So for some reason, Log.e and Log.wtf works but not others.Thank you for your guidance – Mandar Sadye Apr 13 '18 at 19:26
  • Okay dude, I will do more RnD for the same. – Khemraj Sharma Apr 13 '18 at 19:32