How to get slf4j-android to honor Logcat logging level?
If you look at the source for slf4j-android, you can see that it calls android.util.Log#isLoggable
to decide if the log entry should be made. The javadoc for isLoggable
says (my emphasis):
Checks to see whether or not a log for the specified tag is loggable at the specified level. The default level of any tag is set to INFO. This means that any level above and including INFO will be logged. Before you make any calls to a logging method you should check to see if your tag should be logged. You can change the default level by setting a system property: 'setprop log.tag. ' Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will turn off all logging for your tag. You can also create a local.prop file that with the following in it: 'log.tag.=' and place that in /data/local.prop.
So by default calling slf4j's Logger.debug
will do nothing. On the other hand, android.util.Log.d
doesn't call isLoggable
, and so the log entry is made.
None of the options mentioned in the javadoc are palatable, which rather renders slf4j's Logger.debug
less than useful. It'd be nice if the logger could be programatically configured to ignore isLoggable
, but at the time of writing this it can't.
See also Does Log.isLoggable returns wrong values?