Perhaps something like this will work. You will need to determine if the cost of new 'instances is better than doing it differently.
logger.debug("This {} and {} with {} ", defer(() -> this), defer(() -> that), defer(() -> compute()));
Then with this ...
import lombok.NonNull; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor(staticName = "defer") public class LogString { @NonNull private final StringGenerator generator; @Override public String toString() { return generator.createString(); } public interface StringGenerator { String createString(); } }
source share