0

Before I did any changes, I printed Log.isLoggable(MYAPP_TAG) for all levels.

I/System.out﹕ MYAPP Loggable Level: [V:false][D:false][I:true][W:true][E:true]

And then I did adb shell setprop log.tag.MYAPP_TAG WARN.

The Log.isLoggable(MYAPP_TAG) message now became

I/System.out﹕ MYAPP Loggable Level: [V:false][D:false][I:false][W:true][E:true]

However, all log messages (Log.v, Log.d, etc) can still be observed in Logcat.

02-03 13:18:28.050    3284-3284/com.XX V/MYAPP_TAG﹕ onServiceConnected
02-03 13:18:28.050    3284-3284/com.XX D/MYAPP_TAG﹕ onServiceConnected

Why is that?

Pierrew
  • 462
  • 5
  • 15
  • Are you trying to hide debug during runtime of a deployed app or are you trying to just suppress it while debugging? – odexcide Feb 03 '15 at 18:24
  • I am trying to suppress it while debugging. – Pierrew Feb 03 '15 at 18:26
  • hmm... wait what's the difference? – Pierrew Feb 03 '15 at 18:27
  • 1
    If it is just for you, you can use [filters on logcat](http://developer.android.com/tools/debugging/debugging-log.html#filteringOutput). If you are trying to permanently remove log entries from other people viewing them, you should check out [this comment](http://stackoverflow.com/questions/2018263/android-logging#comment5791618_2019563). – odexcide Feb 03 '15 at 18:41
  • This is a good answer if you are trying to hide logs in production (release): http://stackoverflow.com/a/2019597/1895218 – odexcide Feb 03 '15 at 18:43

1 Answers1

2

I think you need to wrap your logs:

if (Log.isLoggable("MY_TAG", Log.VERBOSE)) {
        Log.v("MY_TAG", "Here's a log message");
}

otherwise android seems to ignore your settings; it seems like the Log.v, Log.d, etc. are not checking against the LogLevel.

Nickolaus
  • 4,785
  • 4
  • 38
  • 60
  • It returns "usage: setprop " – Pierrew Feb 03 '15 at 18:23
  • This solution would be pretty verbose with a lot of log messages and add more overhead. Check out this solution http://stackoverflow.com/questions/2018263/android-logging/2019597#2019597 – odexcide Feb 03 '15 at 19:03