File: FloggerRedundantIsEnabled.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (19 lines) | stat: -rw-r--r-- 585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Guarding flogger log statements with an explicit log level check is redundant,
since the log statement already contains the desired log level and is
inexpensive to evaluate if the specified log level is disabled.

This is redundant:

```java
if (logger.atInfo().isEnabled()) {
   logger.atInfo().log(\"blah\");
}
```

If the log statement's *arguments* are expensive to evaluate, consider using
lazy argument evaluation
(https://google.github.io/flogger/examples#logging-with-lazy-argument-evaluation-java8):

```java
logger.atFine().log(\"Value: %s\", lazy(() -> process(x, y)));
```