You have several options.
1) Use String.format () _logger.log(Level.INFO, String.format("[%s] %s enabled", car, dog)) .
2) Use StringBuilder.append() or String.concat () `.
Example: _logger.log(Level.INFO, new StrinBuilder(car).append(" text ").append(dog));
This is essentially what javac does in optimization.
3) Ignore the warning, because it does not matter the effectiveness. If you really care about speed, you wonβt register things. Logging takes a lot of time, and the difference between formatting strings and adding a string is very small relative to the time taken to write the log.
source share