Package com.google.common.flogger
Class LazyArgs
- java.lang.Object
-
- com.google.common.flogger.LazyArgs
-
public final class LazyArgs extends Object
Static utility methods for lazy argument evaluation in Flogger. Thelazy(LazyArg)method allows lambda expressions to be "cast" to theLazyArginterface.In cases where the log statement is strongly expected to always be enabled (e.g. unconditional logging at warning or above) it may not be worth using lazy evaluation because any work required to evaluate arguments will happen anyway.
If lambdas are available, users should prefer using this class rather than explicitly creating
LazyArginstances.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> LazyArg<T>lazy(LazyArg<T> lambdaOrMethodReference)Coerces a lambda expression or method reference to return a lazily evaluated logging argument.
-
-
-
Method Detail
-
lazy
public static <T> LazyArg<T> lazy(LazyArg<T> lambdaOrMethodReference)
Coerces a lambda expression or method reference to return a lazily evaluated logging argument. Pass in a compatible, no-argument, lambda expression or method reference to have it evaluated only when logging will actually occur.
Evaluation of lazy arguments occurs at most once, and always in the same thread from which the logging call was made.logger.atFine().log("value=%s", lazy(() -> doExpensive())); logger.atWarning().atMostEvery(5, MINUTES).log("value=%s", lazy(stats::create));Note also that it is almost never suitable to make a
toString()call "lazy" using this mechanism and, in general, explicitly callingtoString()on arguments which are being logged is an error as it precludes the ability to log an argument structurally.
-
-