Create an Android Lint rule to find guarded log invocations
The Bluetooth stack sets a process default log level, which allows the Android Log framework to properly enforce wheth a log invocation fires based on the set log level for the tag. You do not need to guard individual log invocations anymore. This lint rule looks for log lines inside conditionals (if, else if, or even else), where the conditionals use variables that appear to be log enforcement variables as part of their logic. Errors are generated for those usages. Because this is mostly name based, this is very much best effort, and will have to be updated as patterns in the stack evolve. This was able to find all the violations in the stack that existed before our refactor though. Usages of Log.isLoggable() in conditionals are reduced to warnings, as there are a few valid usages to prevent expensive log operations in code. In general, we expect these usages to be minimal and hope developers will consider altering log statements to avoid usages. Run this lint rule together with others using `m Bluetooth-lint`. Results are available in txt/xml/html format in the build output artifacts. See the README for more details. Tag: #feature Bug: 315046089 Flag: EXEMPT, tooling change Test: atest BluetoothLintCheckerTest --host Change-Id: I175f908f97567ed6638af6026f4caf83acd57e60
Loading
Please register or sign in to comment