To explain why this happens:
According to AOSP source code you can log with any tag you want. The problem is in Log.isLoggable
.
Log.isLoggable
checks the system property log.tag.<YOUR_TAG>
if the priority you want to log is enabled. Here's documentation of this mechanism:
public static boolean isLoggable (String tag, int level)
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.
Source: https://developer.android.com/reference/android/util/Log#isLoggable(java.lang.String,%20int)
Below API 26 (Oreo) the limit of system property keys was 31 characters. And "log.tag.".length() + 23
equals 31. If you call Log.isLoggable
below Android Oreo with a tag longer than 23 characters it will throw, as described in the source code. Since Android O this limit no longer applies.
The Lint rule exists just to shield you from all these (typically) unnecessary details.
The documentation for Log.isLoggable
also states the IllegalArgumentException
will not be thrown since API 24, which according to my findings, is wrong. Follow: https://issuetracker.google.com/issues/124593220